[R] reshape package does not recognize second id variable

Keith Schnakenberg keith.schnakenberg at gmail.com
Mon Sep 29 01:45:25 CEST 2008


I am trying to use the reshape package for the first time. I have two  
waves of a survey, so the id variables include a subject  
identification number and a variable denoting the wave of the survey.

I used the following arguments:

library(reshape)
svy.melt <- melt(svy, id=c("id", "WAVE"))
svy.wide <- cast(svy.melt, id ~ WAVE + ...)

and got the following error:

"Error in check_formula(formula, varnames) :
   Formula contains variables not in list of known variables"

I check to make sure variable name is right, and it is:

summary(svy$WAVE)
    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
    1.00    1.00    1.00    1.47    2.00    2.00
________________________

I use the same code on some fake data with different results:

id <- c(seq(1, 500, 1), seq(1, 500, 1))
x1 <- rnorm(1000)
x2 <- rnorm(1000)
x3 <- rnorm(1000)
x4 <- rnorm(1000)
x5 <- rnorm(1000)
x6 <- rnorm(1000)
x7 <- rnorm(1000)
x8 <- rnorm(1000)
x9 <- rnorm(1000)
x10 <- rnorm(1000)
wave <- c(replicate(500, 1), replicate(500, 2))

fake <- as.data.frame(cbind(id, x1, x2, x3, x4, x5, x6, x7, x8, x9,  
x10, wave))
names(fake) <- c("id", "x1", "x2", "x3", "x4", "x5", "x6", "x7",  
"x8", "x9", "x10", "wave")

fake.melt <- melt(fake, id=c("id", "wave"))
fake.wide <- cast(fake.melt,  id ~ wave + ...)

This works quite nicely, and the resulting dataset looks like it should.

Theories?

Thanks!



More information about the R-help mailing list