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
1 answer

Subtotals in columns using reshape2

I have spent some time now learning reshape2 and plyr but I still do not get it. This time I have a problem with (a) subtotals and (b) passing different aggregate functions. Here an example using data from a tutorial on the blog of mrdwab #…
user1043144
  • 2,680
  • 5
  • 29
  • 45
0
votes
1 answer

ggplot, facets, and changing color in a series

I've got sensor data that looks like this: tm <- seq(1,17) chg <- c(13.6,13.7,13.8,13.9,14.1,14.2,14.4,14.6,14.7,14.9,14.9,15.0,15.0,13.7,13.7,13.6,13.7) batt_A <- c( 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, …
wylbur
  • 87
  • 7
0
votes
1 answer

lm fitting multiple subsets of a data.frame

I am running some simulation where I want to fit a linear model to subsets of my data: library(reshape2) library(plyr) all <- mutate(iris, mean_width = ave(Petal.Width, Petal.Length)) str(all) ## want to minimise sum(|y*polynomial(x) - z|^2) for…
baptiste
  • 75,767
  • 19
  • 198
  • 294
0
votes
1 answer

How to reshape data.frames in a list?

I have a list like this A <- data.frame(a = c(1, 2), b = c(3, 4)) B <- data.frame(c = c(1, 2), d = c(3, 4)) g <- list(var1 = A, var2 = B) producing > g $var1 a b 1 1 3 2 2 4 $var2 c d 1 1 3 2 2 4 Now I want to transpose list elements like…
jrara
  • 16,239
  • 33
  • 89
  • 120
-1
votes
1 answer

Reshaping/Deduping long data to wide in R

I've been trying to reshape this long data into wide format by ID within excel with no luck. I tried using dcast but it did not give me the results I was expecting. I've attached a csv of how the data is currently formatted in cells: (a1:c10), and…
willr
  • 7
  • 1
-1
votes
1 answer

How do I convert a dataset with 1 column per day to only 1 date column (days) with R

I have a dataset with birds observations. I have one column for each day of the month (31). If the bird is seen this day, it has the "place" info (where it has been seen). Can someone help we with a code that can merge these 31 columns (days) into…
Andre230
  • 145
  • 1
  • 9
-1
votes
2 answers

Pivot / Reshape data

My sample data looks like this: data <- read.table(header=T, text=' pid measurement1 Tdays1 measurement2 Tdays2 measurement3 Tdays3 measurment4 Tdays4 1 1356 1435 1483 1405 …
-1
votes
1 answer

R Long to wide with count and sum

I have a data as below: #dt Method ID Source Amt A 1 X 10 A 1 Y 20 C 1 Z 30 B 2 Y 15 D 2 Z 10 C 3 X 20 D …
Peter Chen
  • 1,464
  • 3
  • 21
  • 48
-1
votes
1 answer

How to encode top 5 values of a column

I would like to encode the Top 5 occurring/frequency of values of 'Code' column in the Dataframe below: ID | Code 1 | A 2 | A 3 | A 4 | F 5 | F 6 | C 7 | C 8 | E 9 | E 10 | D 10 | D 11 | B 12 | G 13 | H The result should look like this: ID…
spidermarn
  • 959
  • 1
  • 10
  • 18
-1
votes
1 answer

Converting many variables from long to wide in R

I wish to convert many variables from long to wide in R. I have clustered data with family as a cluster, and in each family individuals. For each individual several measured variables, each measured more than once. In the example below, you can see…
user2899944
  • 249
  • 2
  • 11
-1
votes
1 answer

Reshaping Data Frame (Spread and Make XTS)

I am trying to reshape a data frame from a long vector to a table with the date being first column (ideally its the index as I want to make this an xts format ultimately) and the place_id's being new columns extending outward from left to right. …
js80
  • 385
  • 2
  • 11
-1
votes
1 answer

R how to use fun.aggregate in dcast to keep discrete values when widening dataframe?

I've been trying to use the dcast() function in reshape2 to widen a large dataframe in R. However, I am not sure what to use for the aggregation function, fun.aggregate that dcast requires because I want to keep the discrete values of the value.var,…
-1
votes
2 answers

Short format to long format in R

This is what my data looks like on excel, where status and events are variables for the mentioned dates. Events columns don't have data. 30/12/2018 31/12/2018 01/01/2019 Status event status event status event delivered …
-1
votes
1 answer

Effectively Create a Matrix from a Dataframe for Large dataset

I am trying to create a matrix from a large dataframe. Here is a sample dataframe df <- data.frame(index=c("x","y","j","ww","rr","ff"), a=c(1,3,3,5,1,6), b=c(2,3,5,3,2,3), c=c(3,2,4,5,6,10), d…
user10316615
-1
votes
2 answers

Is there a way to create a subsetted pivot table without aggregated values?

I've been fighting with these problem for a while, but is there a way to get this in R? Source Table ╔═══════════╦══════╦═══════╗ ║ TEST_NAME ║ SBNO ║ VAL ║ ╠═══════════╬══════╬═══════╣ ║ Test1 ║ 1 ║ 0.304 ║ ║ Test1 ║ 2 ║ 0.31 ║ ║…
Rodrigo Guinea
  • 328
  • 4
  • 16