Reshape a series of repeated data in R -


i have data frame in wide format repeated measurments

id method    day1 day2 day3 1           4,5   6    5,6 2.  b          3   2,5    5 3   c          2    4,2   3 

i want reshape format

method    time  value        day1    4,5        day2     6        day3     5,6 b        day1     3 b        day2     2,5 b        day3     5 c................... 

but reshape function changing wide long gives me each group seperately, 1 have idea reshaping in order?

we can use melt reshape2 convert 'wide' 'long' format. specify column index in measure.

library(reshape2) dm <- melt(df1, measure=3:5)[-1] 

and order 'method' column expected output

dm1 <- dm[order(dm$method),] row.names(dm1) <- null dm1 #    method variable value #1          day1   4,5 #2          day2     6 #3          day3   5,6 #4      b     day1     3 #5      b     day2   2,5 #6      b     day3     5 #7      c     day1     2 #8      c     day2   4,2 #9      c     day3     3 

data

df1 <- structure(list(id = c(1, 2, 3), method = c("a", "b", "c"), day1 = c("4,5",  "3", "2"), day2 = c("6", "2,5", "4,2"), day3 = c("5,6", "5",  "3")), .names = c("id", "method", "day1", "day2", "day3"), class = "data.frame", row.names = c(na, -3l)) 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -