[Rd] Re: desiderata for data manipulation
Peter Dalgaard BSA
p.dalgaard@biostat.ku.dk
01 Nov 2000 15:32:07 +0100
rossini@blindglobe.net (A.J. Rossini) writes:
> MM> Dear Tony, can you elaborate what you are missing here for R?
>
> In R, it would be a simple command to reshape a dataframe, from a
> single-observation per individual (or other unit having repeated
> measurements) to multiple lines (one per measurement). Quite often,
> in building models, I'll switch between wide/long versions of the data
> set to build useful variables for modeling.
Almost, but not quite stack()/unstack()...
The basic cases of "reshape long" looks like it would be a piece of
cake to model over the subset() and stack() functions. "reshape wide"
looks a little more tricky, unless you want to brutally assume that
you're dealing with the result of a previous "reshape long".
(The problem would be that in principle you'd know what to do with
A B Y
1 1 0.1 A Y1 Y2
1 2 0.3 ----> 1 0.1 0.3
2 1 0.7 2 0.7 0.9
2 2 0.9
but suppose there's a fifth line as in
A B Y
1 1 0.1
1 2 0.3
2 1 0.7
2 2 0.9
2 2 1.1
Then you'd have two candidates for the value of Y2 for A==2 and it
wouldn't help to assume that there are really two cases with A==2,
because you can't really be sure about to which case the Y1 should
belong.)
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._