[R] reshape

juli g. pausas juli at ceam.es
Sat Oct 12 20:27:26 CEST 2002


I'd like to convert a data.frame from (long format):
gen   maxh  resp
1         12.3   y
.           .       .
.           .       .
where resp is a factor with levels "y" and "n"
to the wide format:

gen  maxh.y  maxh.n
.           .       .
.           .       .

I've done it as follows:

maxh.y <- split(maxh, resp)$y
gy <- split(gen, resp)$y
yes <- data.frame(hr, gen=gy)

maxh.n <- split(maxh, resp)$n
gn <- split(gen, resp)$n
no <- data.frame(hn, gen=gn)

wide <- merge(yes, no, by= "gen") # gen maxh.y maxh.n

This worked well, but would it be possible to do it with reshape? I've
tried but I didn't succeed.
Thanks

Juli

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list