As I mentioned, all you need is a time variable, and you should be fine.
Mark Miller shows the basic approach of R and creates a time variable manually.
Here you can automatically create a time variable and an equivalent command for dcast
from the "reshape2" package:
#
Self-Ad Warning
Since this type of question arises several times, and since many datasets do not always have a unique identifier, I implemented the above option as a function named getanID
in my package βsplitstackshapeβ. In its current version, it hardcodes the variable name βtimeβ as β.β id ". If you use this, follow these steps:
library(splitstackshape) library(reshape2) df <- getanID(df, id.vars=c("V1", "V2")) dcast(df, V1 + V2 ~ .id, value.var = "V3")
source share