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

Reshaping large dataset in R

I am trying to reshape a large dataset and have a problem not getting the results in the right order as I want to. Here is what the data looks like: GeoFIPS GeoName IndustryID Description X2001 X2002 X2003 X2004 X2005 10180 Abilene, TX …
Wolf
  • 562
  • 1
  • 7
  • 19
-1
votes
2 answers

Reshaping a data frame and setting flag variables

I want to reshape my data frame from the df1 to df2 as appears below: df1 <- ID TIME RATEALL CL V1 Q V2 1 0 0 2.4 10 6 20 1 1 2 0.6 10 6 25 2 0 0 3.0 15 7 30 2 5 3 3.0 16 8 15 into…
Amer
  • 2,131
  • 3
  • 23
  • 38
-1
votes
1 answer

Use of Reshape2 for creation of new dataframe

I am having trouble using the reshape2 package for the following purpose. I have a dataframe which looks like: ID = c("1") TIME1 = c("0.5") TIME2 = c("1") TIME3 = c("2") TIME4 = c("5") DF = data.frame(ID, TIME1, TIME2, TIME3, TIME4) I would like…
ykl
  • 397
  • 2
  • 3
  • 13
-1
votes
2 answers

R box plot using factors in multiple columns

I am trying to visualise my data using R box plot and got stuck. My data looks as follows: id var.1 var.2 ... var.n value a 0 1 ... 2 1.7 b 2 1 ... 0 1.4 ... ... ... ... ... ... a 1 2 ... 2 5.3 b 1 …
kiero
  • 121
  • 1
  • 7
-1
votes
1 answer

Reshape a dataframe repeating columns in R

I would like to reshape a dataframe and repeat some informations about Name strings ("Pro1", "Pro2" and "Pro3"). My input: Name Chr Position NE001 NE002 NE003 Pro1 1 25 -0.3 0.2 0.4 Pro2 2 23 -0.4 0.2 -0.3 Pro3 3 …
user3091668
  • 2,230
  • 6
  • 25
  • 42
-1
votes
1 answer

reshape dataframe based on string values

I want to melt a dataframe into long format based on the unique values in a string variable. Some example data: df1 <- structure(list(lllocatie = structure(c(3L, 13L, 5L, 10L, 4L, 32L, 10L, 10L, 22L, 4L, 36L, 37L, 31L, 15L, 23L, 20L, 34L, 8L, 35L,…
Jaap
  • 81,064
  • 34
  • 182
  • 193
-1
votes
1 answer

calculating differences in times, data grouped by rows

I have a data set in the following format ID DATETIME VALUE 1 4/2/2012 10:00 300 1 5/2/2012 23:00 150 1 6/3/2012 10:00 650 2 1/2/2012 10:00 450 2 2/2/2012 13:00 240 3 6/5/2012 09:00 …
Matthew
  • 19
  • 1
-1
votes
1 answer

How to get accumulated/cumulative row-wise sum with dcast in reshape2

Using dcast from the reshape2 library in R I aggregate data (sum) library('reshape2') DF <- data.frame(Cohort=rep("", 9), Weeks=rep("", 9), myvalue=rep(0, 9), stringsAsFactors=FALSE ) DF[1, ] <- c("2012_30","0",0.02) DF[2, ] <-…
Cilvic
  • 3,417
  • 2
  • 33
  • 57
-2
votes
1 answer

How best to use R to reshape dataframe from long to wide and combine values

I have a dataframe of about 2000 rows and 3 columns. In essence, I want to reshape this dataframe to be wider than longer. This is an example of my current…
Becky
  • 9
  • 4
-2
votes
2 answers

Reshaping a dataframe with a huge character column into several numeric columns in R

I have a dataset with a complex column results as (character class). Data sample is here. date_agenda id_question id_event results 2020-09-04 202009043 7426 …
Anakin Skywalker
  • 2,400
  • 5
  • 35
  • 63
-2
votes
1 answer

How to reshape the data in R , apply top date row as column and group by id in

Hi i have the data like this date 2020/06/10 2020/06/10 2020/06/10 2020/06/11 2020/06/11 2020/06/11 id x y z x y z 10432 0 0 0 0 …
Aditya
  • 13
  • 5
-2
votes
1 answer

Reshape wide format (87 items) into long format 4 variables

I have a data frame in a wide format (four variables that are rated from 1 to 7) which are repeated for 87 items. My data frame looks like this Subject| Variable 1 for item 1| Variable 2 for item 1| Variable 3 for item 1| Variable 4 for item 1 …
-2
votes
1 answer

R: how to reshape data frame with the first two columns as independent variable?

I am trying to set up a data frame with month and site as the independent variable, and length as the only dependent variable. But I am not sure which function can help. Currently, I have a long data frame, and I want to make it wide. I tried to use…
Rhyn
  • 135
  • 14
-2
votes
2 answers

complex data restructuring - wide to long (multiple columns)

I want to do a restructuring as above, and I'm struggling with just using gather() as there are multiple columns to make... does anyone know a way to do this?
llbia
  • 123
  • 2
-2
votes
1 answer

Removing unwanted Observation, and calculating Time Difference

I have a data frame, when an id is audited it can be either Passed or failed at that particular time. how to calculate, the sum of all the time taken to change status from Failed to Passed state w.r.t id's. If an id has failed, failed, Passed state.…
Xenus
  • 43
  • 4