You are here

Error running analysis after deleting rows from data frame

3 posts / 0 new
Last post
dstanley4's picture
Joined: 08/07/2012 - 12:32
Error running analysis after deleting rows from data frame

Hi Everyone,
Using metaSEM and loving it. But, I've encountered a problem using metaSEM with a data frame after I have deleted rows from that data frame -- or created a new data frame that is a subset of the rows in the original data frame. Fortunately, I've also discovered a work around - but the error is an odd one. I have attached the relevant files, but I'll describe it in detail here.

Imagine I have a data set then runs fine in metaSEM. If I create new data frame that is a subset of the original data frame the new data frame will not run in metaSEM. I've tried various ways of creating the new data frame, but the results is always the same. I get the following error:

Error in `$<`(`*tmp*`, "time", value = c(1L, 0L, 1L, 2L, 3L, :
replacement has 19 rows, data has 17

Oddly, I've found that if I take the data frame that will not run, save it to disk, load it, and run it, everything is fine.
Looks like a fix may possibly be needed in metaSEM or OpenMx - since the particular data doesn't seem to be the issue here.


print("Running: All Data")

#if you uncomment this next bit, the program will crash with the above error
#print("Running Subset Data: Error")

#This work around save the day though...
print("Running Subset Data: saved and reloaded")

Binary Data errorDemonstrationScript.R552 bytes
File ExampleData2.csv329 bytes
Mike Cheung's picture
Joined: 10/08/2009 - 22:37
The levels of GRP are

The levels of GRP are different in these two datasets:
> levels(testDataSubset$GRP)
[1] "A" "B" "C" "D" "E" "F"
> levels(testDataSubsetLoad$GRP)
[1] "B" "C" "D" "E" "F"

A workaround is to use as.character(GRP):
m3 <- meta3(y=r,v=va,cluster=as.character(GRP),data=testDataSubset)

I will include as.character() in the next release. Thanks.


dstanley4's picture
Joined: 08/07/2012 - 12:32

Thanks for this solution. I tried it immediately - and it solved my problems. Sorry to take a while to get back to this forum to thank you - busy time of year.

Log in or register to post comments