Skip to content
Back to skills

Reshape2

ASecurity

R reshape2 package for data reshaping. Use for melting and casting data between wide and long formats.

  • 5 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added June 4, 2026
dataapi

Works with

  • api

Security analysis

A100/100

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill reshape2 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Reshape2?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Reshape2
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-reshape2/badge)](https://www.skillsdirectory.com/skills/leolin990405-reshape2)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: reshape2
description: R reshape2 package for data reshaping. Use for melting and casting data between wide and long formats.
---

# reshape2

Flexibly reshape data.

## Melt (Wide to Long)

```r
library(reshape2)

# Basic melt
long_df <- melt(wide_df)

# Specify id variables
long_df <- melt(wide_df, id.vars = c("id", "name"))

# Specify measure variables
long_df <- melt(wide_df,
  id.vars = "id",
  measure.vars = c("var1", "var2", "var3")
)

# Custom column names
long_df <- melt(wide_df,
  id.vars = "id",
  variable.name = "metric",
  value.name = "score"
)
```

## Cast (Long to Wide)

```r
# dcast for data frames
wide_df <- dcast(long_df, id ~ variable)

# With aggregation
wide_df <- dcast(long_df, id ~ variable, fun.aggregate = mean)
wide_df <- dcast(long_df, id ~ variable, fun.aggregate = sum)

# Multiple id variables
wide_df <- dcast(long_df, id + name ~ variable)

# acast for arrays/matrices
arr <- acast(long_df, id ~ variable)
```

## Formula Syntax

```r
# row_var ~ col_var
dcast(df, id ~ variable)

# Multiple row variables
dcast(df, id + group ~ variable)

# Multiple column variables
dcast(df, id ~ var1 + var2)

# All variables on one side
dcast(df, ... ~ variable)  # All others as rows
dcast(df, id ~ ...)        # All others as columns
```

## Handling Missing Values

```r
# Fill missing with value
wide_df <- dcast(long_df, id ~ variable, fill = 0)
wide_df <- dcast(long_df, id ~ variable, fill = NA)

# Drop missing
wide_df <- dcast(long_df, id ~ variable, drop = TRUE)
```

## Multiple Value Columns

```r
# Melt multiple measure columns
long_df <- melt(wide_df,
  id.vars = "id",
  measure.vars = list(
    c("a1", "a2", "a3"),
    c("b1", "b2", "b3")
  ),
  variable.name = "time",
  value.name = c("metric_a", "metric_b")
)
```

## Comparison with tidyr

```r
# reshape2::melt = tidyr::pivot_longer
# reshape2::dcast = tidyr::pivot_wider

# reshape2 is faster for large datasets
# tidyr has cleaner syntax
# Both achieve same results
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.