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
7
votes
2 answers

R Violin plots and boxplots together, make fill behave differently only for boxplots

Ok, so I want to plot violin plots together with white boxplots, but my data is a little bit tricky. I melted data from data.frame with several columns, each of which has values corresponding to factor with two levels, here is approximation of my…
Poiu Rewq
  • 182
  • 13
7
votes
1 answer

In R, using melt(), how can I hide warning messages?

I'm melting some data and don't want to provide an id.var parameter to melt. The data melts fine, but I get the "No id variables; using all as measure variables" Is there a way to prevent that message from coming up, or a way to say…
Adam Price
  • 810
  • 2
  • 11
  • 21
7
votes
2 answers

Combine data frame rows in R based on multiple columns

I have a data frame in R which has one individual per line. Sometimes, individuals appear on two lines, and I would like to combine these lines based on the duplicated ID. The problem is, each individual has multiple IDs, and when an ID appears…
njc
  • 126
  • 1
  • 6
7
votes
2 answers

Spread vs dcast

I have a table like this, > head(dt2) Weight Height Fitted interval limit value 1 65.6 174.0 71.91200 pred lwr 53.73165 2 80.7 193.5 91.63237 pred lwr 73.33198 3 72.6 186.5 84.55326 pred lwr 66.31751 4 78.8 187.2…
TheRimalaya
  • 4,232
  • 2
  • 31
  • 37
7
votes
5 answers

Converting Column Values into Their Own Binary Encoded Columns (Dummy Variables)

I have a number of CSV files with columns such as gender, age, diagnosis, etc. Currently, they are coded as such: ID, gender, age, diagnosis 1, male, 42, asthma 1, male, 42, anxiety 2, male, 19, asthma 3, female, 23, diabetes 4, …
Greenstick
  • 8,632
  • 1
  • 24
  • 29
7
votes
3 answers

Reshaping a Table in R - Better Approach?

I have a data frame of factors called questions q1 q2 q3 A A B C A A A B C That I want to reshape into question answer freq 1 A 2 1 B 0 1 C 1 2 A 2 2 B 1 2 C 0 3 A…
user2689931
  • 383
  • 1
  • 6
  • 15
7
votes
2 answers

Duplicating observations of a dataframe, but also replacing specific variable values in R

I am looking for some advice on some data restructuring. I am collecting some data using Google Forms which I download as a csv file and looks something like the following: # alpha beta option # 6 8, 9, 10, 11 …
jalapic
  • 13,792
  • 8
  • 57
  • 87
7
votes
1 answer

melt.data.frame() changes behavior how POSIXct columns are printed

Melting the dataframe t.wide changes how the column "time" (class POSIXct) is printed. t.wide <- data.frame(product=letters[1:5], result=c(2, 4, 0, 0, 1), t1=as.POSIXct("2014-05-26") + seq(0, 10800,…
Tobias
  • 422
  • 2
  • 6
7
votes
1 answer

dcast fun.aggregate parameters

In the R package reshape2, does the dcast() function parameter fun.aggregate= have the ability to accept parameters itself? For instance: dcast(dataFrame, x ~ y, value.var = 'z', fun.aggregate = mean(na.rm = TRUE)) I'm asking because I use my own…
StinkySocks
  • 812
  • 1
  • 13
  • 20
7
votes
4 answers

R - reorganizing a molten data.frame with variable pairs

Sorry I'm not particularly articulate in the post title..I hope my example will be clearer! If I start out with a data frame: test.df <- data.frame(group=c(rep("a",4), rep("b",4)), var=rep(1:4,2), min=…
maja zaloznik
  • 660
  • 9
  • 24
7
votes
3 answers

Speed up `strsplit` when possible output are known

I have a large data frame with a factor column that I need to divide into three factor columns by splitting up the factor names by a delimiter. Here is my current approach, which is very slow with a large data frame (sometimes several million…
Noam Ross
  • 5,969
  • 5
  • 24
  • 40
7
votes
3 answers

Reorganizing data from 3 rows to 1

I need to reorganize data from a csv file that contains mostly repeating data. I have the data imported into R in a dataframe but I am having trouble with the following: ID Language Author Keyword 12 eng Rob COLOR=Red 12 eng …
Ray
  • 73
  • 2
7
votes
3 answers

POSIXct values become numeric in reshape2 dcast

I'm trying to use dcast from the latest reshape2 package (1.2.1) to denormalize a data frame (or data.table) where the value.var is a POSIXct type, but in the resulting data frame, the date values have lost their POSIXct class and become numeric.…
gkaupas
  • 179
  • 1
  • 7
7
votes
3 answers

Solidifying a melted data frame?

Assuming I have a melted data.frame that looks like this: variable value 1 A -0.19933093 2 A -1.19043346 3 A -1.32248172 4 A -1.98644507 5 A -0.07930953 6 B -0.10074686 7 B …
Maiasaura
  • 32,226
  • 27
  • 104
  • 108
6
votes
3 answers

Converting data from wide to long format when id variables are encoded in column header

I am relatively new to R and have data in wide format as follows subject_id age sex treat1.1.param1 treat1.1.param2 treat1.2.param1 …
Jan
  • 63
  • 3