From p.dalgaard@biostat.ku.dk  Wed Nov  1 14:32:07 2000
From: p.dalgaard@biostat.ku.dk (Peter Dalgaard BSA)
Date: 01 Nov 2000 15:32:07 +0100
Subject: [Rd] Re: desiderata for data manipulation
In-Reply-To: rossini@blindglobe.net's message of "01 Nov 2000 05:42:15 -0800"
References: <20001030222745.B11703@ps2-4.ucl-41> <877l6qylxd.fsf@jeeves.blindglobe.net> <20001031192804.A1043@ps2-4.ucl-41> <87snpceqsz.fsf@jeeves.blindglobe.net> <14847.50772.578389.86697@gargle.gargle.HOWL> <87k8ang66g.fsf@jeeves.blindglobe.net>
Message-ID: <x2u29rhifs.fsf@blueberry.kubism.ku.dk>

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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] Re: desiderata for data manipulation
Peter Dalgaard BSA