Questions tagged [reshape2]

The reshape2 package in R contains functions that allow data to be transformed into more convenient forms.

reshape2 is an package for flexibly restructuring and aggregating data. Its primary use is ing data between wide format with repeated measurements in separate columns of the same record and long format with the repeated measurements in separate records.

reshape2 succeeds the reshape package, and is succeeded by the package.

Repositories

Other resources

Related tags

1177 questions
72
votes
3 answers

Comparing gather (tidyr) to melt (reshape2)

I love the reshape2 package because it made life so doggone easy. Typically Hadley has made improvements in his previous packages that enable streamlined, faster running code. I figured I'd give tidyr a whirl and from what I read I thought gather…
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519
65
votes
2 answers

reshape2 melt warning message

I'm using melt and encounter the following warning message: attributes are not identical across measure variables; they will be dropped After looking around people have mentioned it is because the variables are different classes; however, that is…
cherrytree
  • 1,561
  • 3
  • 16
  • 33
64
votes
3 answers

Is it possible to use spread on multiple columns in tidyr similar to dcast?

I have the following dummy data: library(dplyr) library(tidyr) library(reshape2) dt <- expand.grid(Year = 1990:2014, Product=LETTERS[1:8], Country = paste0(LETTERS, "I")) %>% select(Product, Country, Year) dt$value <- rnorm(nrow(dt)) I pick two…
mpiktas
  • 11,258
  • 7
  • 44
  • 57
57
votes
2 answers

Grouped bar plot in ggplot

I have a survey file in which row are observation and column question. Here are some fake data they look like: People,Food,Music,People P1,Very Bad,Bad,Good P2,Good,Good,Very Bad P3,Good,Bad,Good P4,Good,Very Bad,Very Good P5,Bad,Good,Very…
S12000
  • 3,345
  • 12
  • 35
  • 51
54
votes
8 answers

Reshaping multiple sets of measurement columns (wide format) into single columns (long format)

I have a dataframe in a wide format, with repeated measurements taken within different date ranges. In my example there are three different periods, all with their corresponding values. E.g. the first measurement (Value1) was measured in the period…
daj
  • 6,962
  • 9
  • 45
  • 79
51
votes
1 answer

No non-missing arguments warning when using min or max in reshape2

I get the following warning when I use min or max in the dcast function from the reshape2 package. What is it telling me? I can't find anything that explains the warning message and I'm a bit confused about why I get it when I use max but not when I…
Tumbledown
  • 1,887
  • 5
  • 21
  • 33
50
votes
1 answer

reshape vs. reshape2 in R

I am attempting to understand why development had shifted from reshape to reshape2 package. They seem to be functionally the same, however, I am unable to upgrade to reshape2 currently due to an older version of R running on the server. I am…
Alex
  • 19,533
  • 37
  • 126
  • 195
43
votes
5 answers

Reshaping wide to long with multiple values columns

I need to reshape my wide table into long format but keeping multiple fields for each record, for example: dw <- read.table(header=T, text=' sbj f1.avg f1.sd f2.avg f2.sd blabla A 10 6 50 10 bA B 12 5 70 11 …
Vasily A
  • 8,256
  • 10
  • 42
  • 76
39
votes
3 answers

can the value.var in dcast be a list or have multiple value variables?

In the help files for dcast.data.table, there is a note stating that a new feature has been implemented: "dcast.data.table allows value.var column to be of type list" I take this to mean that one can have multiple value variables within a list, i.e.…
AlexR
  • 791
  • 2
  • 8
  • 22
38
votes
4 answers

R: "Unary operator error" from multiline ggplot2 command

I'm using ggplot2 to do a boxplot comparison of two different species, as indicated by the third column shown below: > library(reshape2) > library(ggplot2) > melt.data = melt(actb.raw.data) > head(actb.raw.data) region expression species 1 …
soosus
  • 1,211
  • 4
  • 18
  • 27
34
votes
1 answer

Why reshape2's Melt cannot capture rownames in the transformation?

I have the following data: Cubn 3.71455160837536 0.237454645363458 Gm9779 2.56051657980096 0.20850752817264 Apod 3.51796703048962 0.195999214485821 What I want to do is to create the 'melted' data such that it gives this var1…
neversaint
  • 60,904
  • 137
  • 310
  • 477
32
votes
7 answers

Compute mean and standard deviation by group for multiple variables in a data.frame

Edit -- This question was originally titled << Long to wide data reshaping in R >> I'm just learning R and trying to find ways to apply it to help out others in my life. As a test case, I'm working on reshaping some data, and I'm having trouble…
user2348358
  • 321
  • 1
  • 3
  • 3
31
votes
2 answers

dcast warning: ‘Aggregation function missing: defaulting to length’

My df looks like this: Id Task Type Freq 3 1 A 2 3 1 B 3 3 2 A 3 3 2 B 0 4 1 A 3 4 1 B 3 4 2 A 1 4 2 B 3 I want to restructure by Id and…
user3315563
  • 495
  • 2
  • 5
  • 10
26
votes
3 answers

how to pivot/unpivot (cast/melt) data frame?

How can I 'unpivot' a table? What is the proper technical term for this? UPDATE: The term is called melt I have a data frame for countries and data for each year Country 2001 2002 2003 Nigeria 1 2 3 UK 2 NA …
pedrosaurio
  • 4,708
  • 11
  • 39
  • 53
26
votes
2 answers

Can dcast be used without an aggregate function?

Possible Duplicate: This R reshaping should be simple, but dcast from reshape2 works without a formula where there are no duplicates. Take these example data: df <- structure(list(id = c("A", "B", "C", "A", "B", "C"), cat = c("SS", "SS", "SS",…
Maiasaura
  • 32,226
  • 27
  • 104
  • 108
1
2 3
78 79