dataframe - How to reshape data frame, header value to column value in R -
i have dataset similar following structure
date obj obj b obj c 12/12/2001 2 3 4 11/12/2001 5 7 6
and want reshape them following structure, panel plot in ggplot2
date value factor 12/12/2001 2 obj 11/12/2001 5 obj 12/12/2001 3 obj b 11/12/2001 7 obj b 12/12/2001 4 obj c 11/12/2001 6 obj c
is there easier way/package other subsetting data , rbind data 1 one? help
in base r, if values reshaped not factor
s, can use stack
:
cbind(mydf[1], stack(mydf[-1])) # date values ind # 1 12/12/2001 2 obja # 2 11/12/2001 5 obja # 3 12/12/2001 3 objb # 4 11/12/2001 7 objb # 5 12/12/2001 4 objc # 6 11/12/2001 6 objc
Comments
Post a Comment