Keith Schnakenberg
2008-Sep-28 23:45 UTC
[R] reshape package does not recognize second id variable
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!
hadley wickham
2008-Sep-29 00:55 UTC
[R] reshape package does not recognize second id variable
On Sun, Sep 28, 2008 at 6:45 PM, Keith Schnakenberg <keith.schnakenberg at gmail.com> wrote:> 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.00What does the output of str(svy) and str(svy.melt) look like? Hadley -- http://had.co.nz/
Seemingly Similar Threads
- reshape "Error in data[, timevar] : incorrect number of dimensions"
- sem package fails when no of factors increase from 3 to 4
- how to add a row vector in a dataframe
- Loops, Paste, Apply? What is the best way to set up a list of many equations?
- Using as.formula() with the reshape package cast