Skip to content

reshape "Error in data[, timevar] : incorrect number of dimensions"

3 messages · Keith Schnakenberg, Dieter Menne, John Kane

#
I have two waves of a survey given to students at various middle  
schools and high schools, with student id numbers for each student. I  
am having difficulty reshaping the file from long to wide.

My code is below:

library(foreign)
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.

Thanks,
Keith
#
Keith Schnakenberg <keith.schnakenberg <at> gmail.com> writes:
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.

summary(svy)

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?

Dieter
#
Try str(svy) and see what formats the seperate variables have.  It may give you a clue as to what is happening.  

An alternative approach is to see if the reshape package can help you.  
See See http://had.co.nz/reshape for more information on the package.
--- On Sat, 9/27/08, Keith Schnakenberg <keith.schnakenberg at gmail.com> wrote: