Hi,

I would like to reshape a data.frame from long to wide format. However, the 
reshape function does not seem to accept data containing rows with duplicate 
idvar and timevar. Building upon the ?reshape example:

summary(Indometh)
wide <- reshape(Indometh, v.names = "conc", idvar = "Subject",
  timevar = "time", direction = "wide")

Indometh2 <- rbind(Indometh, Indometh2[1,])
wide <- reshape(Indometh2, v.names = "conc", idvar = "Subject",
  timevar = "time", direction = "wide")

In the 2nd call, reshape drops the duplicate. In a real world, the process I am 
working on will handle data with unknown number of duplicates like the one I 
have manually create above.

One "brute force" way to circumvent this would be to pre-process the data, 
identify the rows with duplicate idvar/timevar combos, and add some suffixes to 
the idvar variable to make the rows unique. Then I would call reshape, and 
finally, I would post-process the data to remove the suffixes... This does not 
seem very elegant.

Is there a more efficient way to go about this?

Thank you

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to