[R] reshape (was: Comparing rows in a dataframe)

Thomas Lumley tlumley at u.washington.edu
Fri Aug 6 18:40:18 CEST 2004


On Fri, 6 Aug 2004, Doran, Harold wrote:

> Hi all:
>
>
>
> I solved the previous stated problem in something of a brute force way
> (but it works). I seem to now be running into one little hiccup using
> reshape. Here is a quick snip of the data in long format:
>
<snip>
>
> Now, I want to reshape this into the wide format. However, when I do I
> get NAs in the stability columns. Here is what I have done and the
> result.
>
> wide<- reshape(tennshort, idvar = c("schid","grade"), timevar = "year",
> v.names="stability", direction="wide")
>

reshape() doesn't support multiple idvars (it isn't documented to).  You
have to do something like

tennshort$ID<-with(tennshort, interaction(schid,grade))
wide<- reshape(tennshort, idvar = "ID", timevar = "year",
 v.names="stability", direction="wide")


This might be a useful extra feature in reshape, as might the ability to
specify multiple time variables (eg year, season)

	-thomas




More information about the R-help mailing list