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

reshape unique strings in rows into columns in R

I would like to reshape my data based in unique string in a "Bull" column (all data frame): EBV Bulls 0.13 NE001362 0.17 NE001361 0.05 NE001378 -0.12 NE001359 -0.14 NE001379 0.13 NE001380 -0.46 NE001379 -0.46 NE001359 -0.68…
user3091668
  • 2,230
  • 6
  • 25
  • 42
0
votes
2 answers

Populate an array using reshape2

I have a data.table object of dimension 421,570 x 16 which stores data for multiple stores. Stores can have different department. This is only a made up example. The dataset is bigger. > head(raw.df) Store Type StoreSize Dept Date…
Gianluca
  • 6,307
  • 19
  • 44
  • 65
0
votes
2 answers

Convert from long wide data fromat to long data format in R with multiple depth headers

Maybe this can't even be done because I have my data in a bad format, but I'm trying to get it from a "kind of" wide format to a long format. If I modify the data in excel first, I know how to do this with melt, but I have a LOT of data, and I'm…
Krone
  • 43
  • 10
0
votes
2 answers

Re-organizing a dataframe

I am trying to re-organize my data frame using reshape2 library. Even though convincing, I am not able to get the expected result. Here is my data.frame on hand. > mydata Destination S1 S2 S3 S4 1 D1 94 87 84…
Raghu
  • 57
  • 8
0
votes
1 answer

Problems with casting a dataframe with text columns

I have this text dataframe with all columns being character vectors. Gene.ID barcodes value A2M TCGA-BA-5149-01A-01D-1512-08 Missense_Mutation ABCC10 TCGA-BA-5559-01A-01D-1512-08 …
0
votes
2 answers

Creating a time variable to melt a data frame

I have a small nagging question that I hope I might be able to get some help on... My data frame has a personID and houseID (as well a distance between the two), though one person may be matched to more than one house. I want to reshape my data so…
bubsy
  • 23
  • 4
0
votes
1 answer

reshape2 - melt - id.vars merged into 1 column

I have this data.frame organized like this: Time.A Z.A Y.A Time.B Z.B Y.B 1 1 -0.10612452 0.6359504 1.414806 -0.4304691 -1.71700868 2 2 1.51152200 -0.2842529 2.437075 -0.2572694 -0.78445901 3 …
zelite
  • 1,478
  • 16
  • 37
0
votes
2 answers

melt giving several value columns

I am reading in parameter estimates from some results files that I would like to compare side by side in a table. But I cant get the dataframe to the structure that I want to have (Parameter name, Values(file1), Values(file2)) When I read in the…
0
votes
2 answers

Melt a array into data.frame but converting one dimension into columns

I would like to convert a array with multiple dimensions (e.g. x, y, z; see 'arr' below) into a data.frame, but keep a dimension in the columns (e.g. z, see 'df2' below). Currently, I use melt and dcast functions in reshape2…
Bangyou
  • 9,462
  • 16
  • 62
  • 94
0
votes
1 answer

given a dataframe of 3 columns, plot the first 2 on 1 axis, and the 3rd on a separate axis below it using ggplot2

I have a dataframe with 4 columns: "x" "colA" "colB" "colC" df <- data.frame(x, colA, colB, colC) df2 <- melt(data=df, id.vars="x") currently I am doing the following ggplot(df2, aes(x=x, y=value, colour=variable)) + geom_line() + facet_wrap(…
DolemiteMofo
  • 39
  • 1
  • 6
0
votes
1 answer

how to use multiple values in cast function?

I have a table with in game user purchases, the columns are: uid levelid created timeid price I want by using the reshape's cast function extract for each unique player the minimum values of "timeid"s (timeid - is the time of purchase in…
andrew-zmeul
  • 121
  • 1
  • 1
  • 10
0
votes
3 answers

How can I reshape a data.table or data.farme in R without adding up the frequencies?

I am trying to reshape the following data.table to like a contingency table(not exactly because I don't want to get frequency as value, I just want 0 or 1): Df: ID CC 990081899A CC2 990081899A CC115 990081899A CC39 990081899A …
nsDataSci
  • 189
  • 2
  • 10
0
votes
1 answer

how dcast a molten dataframe accross multiple dimentions?

I am a bit confused on how to use dcast function even after reading the documentation. I am trying to dcast a molten dataframe as below > head(res) factoroneid factortwoid val 1 1 1 5.8223670800 2…
Alok
  • 3,160
  • 3
  • 28
  • 47
0
votes
2 answers

Reshape a dataframe with reshape2

I have this data.frame: habitat <- data.frame( proportion = c(0.053, 0.139, 0.050, 0.756, 0.001, 0.084, 0.000, 0.011, 0.005, 0.066, 0.810, 0.025), habitat = c("Non-irrigated arable land", "Pastures", "Natural grasslands", "Intertidal…
luciano
  • 13,158
  • 36
  • 90
  • 130
0
votes
1 answer

adding row/column total data when aggregating data using plyr and reshape2 package in R

I create aggregate tables most of the time during my work using the flow below: set.seed(1) temp.df <- data.frame(var1=sample(letters[1:5],100,replace=TRUE), var2=sample(11:15,100,replace=TRUE)) temp.output <- ddply(temp.df, …
lokheart
  • 23,743
  • 39
  • 98
  • 169