[R] reshape "Error in data[, timevar] : incorrect number of dimensions"
dieter.menne at menne-biomed.de
Sun Sep 28 12:04:04 CEST 2008
Keith Schnakenberg <keith.schnakenberg <at> gmail.com> writes:
> svy <- read.spss("studsur4.SAV")
> svy.wide <- reshape(svy, timevar="WAVE", idvar="id", direction="wide")
> "id" is the student identification number, and "WAVE" takes values 1
> and 2. I get the following error:
> Error in data[, timevar] : incorrect number of dimensions
> I would provide reproducible code but I can't reproduce the error
> with any other data. I would appreciate any conjectures as to why
> this is happening.
If you believe it's a problem with your data, do the following:
Create an artificial data set that works with you reshape command. reshape is
one of the most twisted functions in R, and I never can use it without reading
the manpages again.
Maybe you can spot something unexpected? Some factor that should not be a
factor? Some NA that should not be there?
Then, remove all data from the set with the exception of the rows 5-8 (< there
is a little superstition in here, you could also use the first row, but
sometime, mainly with read.table, the first rows are specially bad). This might
give you some other error, when reshape fails because of missing cells, but it
could help nevertheless.
Then, remove the first half of the data, then the second half. Problem gone?
More information about the R-help