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:
grade stability year schid
6 Grade 4 3 2001 100005
7 Grade 4 3 2002 100005
8 Grade 4 2 2003 100005
10 Grade 5 2 2001 100005
11 Grade 5 2 2002 100005
12 Grade 5 1 2003 100005
18 Grade 4 2 2001 100010
19 Grade 4 2 2002 100010
20 Grade 4 2 2003 100010
22 Grade 5 2 2001 100010
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")
grade schid stability.2001 stability.2002 stability.2003
6 Grade 4 100005 NA NA NA
10 Grade 5 100005 NA NA NA
18 Grade 4 100010 NA NA NA
22 Grade 5 100010 NA NA NA
What appears to be the reason I get NAs in the newly created stability
columns?
Thank you
Harold
[[alternative HTML version deleted]]
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