[R] help with colsplit (reshape)

hadley wickham h.wickham at gmail.com
Fri Jun 13 23:47:55 CEST 2008

> Right, there is no time associated with this variable. So I tried again,
> treating it as an id:
> M.Data <- melt(Data, id = c("pid", "predA"))
> From here I was able to achieve the desired result, as follows:
> M.Data <- data.frame(M.Data, colsplit(M.Data$variable, split = "\\.",
> names=c("measure", "time")))
> M.Data$variable <- M.Data$measure
> M.Data <- M.Data[-5]
> L.Data <- cast(M.Data, ... ~ variable)
> This is perhaps a bit inelegant but it works! I'm interested in knowing if
> there is a better way to do it, but I'm happy that I've at least figured out
> this much. As always I'm humbled by the generosity of people who not only
> make their software available but also take the time to answer questions on
> this list. Thank you!

You're welcome.  And don't worry too much about data cleaning routines
being elegant - it's very very hard to write elegant code to clean up
something that's not at all elegant.



More information about the R-help mailing list