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

Reshaping a dataframe in R

I need some help to re-design the output of a function that comes through an R package. My scope is to reshape a dataframe called output_IMFData in a way that look very similar to the shape of output_imfr. The codes of a MWE reproducing these…
msh855
  • 1,493
  • 1
  • 15
  • 36
-1
votes
2 answers

Sumif and Pivoting in R (reshape2, melt, cast, merge..)

I have a dataframe that looks like: df-> Elmt1 Elmt2 Type 1 1 8 Red 2 5 3 Blue 3 5 1 Blue 4 7 2 Red 5 3 2 Red 6 5 2 Red And a vector that…
Bryan Han
  • 67
  • 6
-1
votes
2 answers

Long to wide format conversion gives duplicate time identifier rows

See the chat transcript before voting to close please I have the following data: > dput(head(q,10)) structure(list(Date = structure(c(1471424400, 1471424400, 1471424400, 1471424401, 1471424401, 1471424406, 1471424407, 1471424415, 1471424417,…
Polar Bear
  • 731
  • 1
  • 7
  • 21
-1
votes
1 answer

ggplot melting and plotting of bar chart

How would I plot a bar chart showing the percentage within gender for each of the different levels of var The data can be built as follows: structure(list(var = structure(c(5L, 5L, 5L, 6L, 5L, 4L, 5L, 6L, 6L, 6L, 5L, 5L, 5L, 6L, 6L, 5L, 6L, 5L, 6L,…
vashts85
  • 1,069
  • 3
  • 14
  • 28
-1
votes
1 answer

R data.table tidying - condense rows based on muliple criteria

***To ask this question I removed a Time column in my below example that exists in my actual data which featured the actual time (with different seconds despite same nominal time) which led to my data having one score per row. When I rounded these…
willz
  • 3
  • 3
-1
votes
3 answers

Reshape2: multiple observations for variable

I have the following sample data: d <- data.frame(id=c(1,1,1,2,2), time=c(1,1,1,1,1), var=runif(5)) id time var 1 1 1 0.373448545 2 1 1 0.007007124 3 1 1 0.840572603 4 2 1 0.684893481 5 2 1 0.822581501 I want to…
wake_wake
  • 1,332
  • 2
  • 19
  • 46
-1
votes
1 answer

Most efficient format for array data for R import?

I'm in the enviable position of being able to set up the format for my data collection ahead of time, rather than being handed some crazy format and having to struggle with it. I'd like to make sure I'm setting it up in a way that minimizes…
JHegg
  • 61
  • 1
  • 10
-1
votes
1 answer

Turning a wide-form matrix into long-form in R (possibly with reshape2 and melt)

I have a matrix which looks (structurally) something like this: id 1st 2nd 3rd 4th 5th [1,] "aaaaa1" "Tesco" "Sainsbury" "M&S" "Waitrose" "Asda" [2,] "bbbbb2" "Sainsbury" "Tesco" …
ajrwhite
  • 7,728
  • 1
  • 11
  • 24
-1
votes
2 answers

R: Making pivot table with dplyr or reshape2 package

I am trying to make simple pivot table in R using dplyr or reshape2 packages as my dataset is too large and R goes out of memory with sqldf. The two columns of my dataset that I want to make a pivot table out of is "Product" and "Cust_Id". I want to…
May Y
  • 179
  • 1
  • 20
-1
votes
1 answer

Need Help reshaping grouped variables in R

I would really appreciate some helpful suggestions for reshaping data in R. I've been looking at related discussions on reshaping between wide and long format with grouped variables, but can't seem to get my data frame to reshape without receiving…
giderk
  • 61
  • 1
  • 7
-1
votes
2 answers

Spread one of multiple grouping variables without applying function

Having trouble getting either tidyr, reshape, or reshape2 to do something I imagine to be simple. Have data that looks like this: agecat year Drug total <1 1999 Amikacin 12 <1 1999 …
jlev514
  • 281
  • 5
  • 15
-1
votes
3 answers

Convert total records per species into record x species matrix

Imagine that I have 9 sampling records for three species distributed as such: sp1 sp2 sp3 3 1 5 What I want to obtain is a records x species matrix, and fill it with 1s and 0s as such: sp1 sp2 sp3 1 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 0…
sca
  • 23
  • 1
  • 5
-1
votes
2 answers

subtracting controls from multiple datasets

Below is a simplified data frame from some qPCR data: sample exprFile reaction_conc 1 A 140701_2014-07-03-15-49 59 2 A 140701_2014-07-03-15-49 70 3 NC_1 140701_2014-07-03-15-49 …
B. Brooks
  • 1
  • 4
-1
votes
1 answer

how to organize a data using a handy function?

It is often said that 80% of data analysis is spent on the cleaning and preparing data. In this aspect I sometimes spent quite some time to shape my data and finally get a data.frame as shown in reproducible example. I want to organize rows as…
Alexander
  • 4,527
  • 5
  • 51
  • 98
-1
votes
2 answers

Missing values using reshape2

My question is very similar to the one posted here. I am trying to use reshape data to turn CRSP data from long format to wide. I have the tickers of S&P companies stacked in one column and I want to make them the columns instead. In my dataframe I…
Bobe Kryant
  • 2,050
  • 4
  • 19
  • 32