0

I am trying to convert an imputed data frame into a mids object using as.mids. There are 5 imputations and the original dataset. It is a long format data frame with 4 waves of BMI measurements and ~11,000 participants. When I run:

mids <- as.mids(df)

I get the following error messages:

'Error in [<- data.frame(*tmp*, j, value = c(X, Y, : replacement has X rows, data has Y'
'Error in .rowNamesDF<-(X, value = value) : duplicate 'row.names' are not allowed'

To correct the latter problem, I tried the code:

colnames(df)[colnames(df)==".id"] <- "id"

This gets rid of the error regarding duplicate row names when I run the as.mids again. I am not sure whether this is changing things that I shouldn't be changing, however.

I have not figured out how to solve the first error.

Can anyone help with sorting this?

I have used as.mids before and it has worked - I can't figure out what is different about this case.

Thanks!

jrcalabrese
  • 2,184
  • 3
  • 10
  • 30
kt99
  • 1
  • 1
  • It seems it is the row's names that causes the error, not the column's names. Try `row.names(data)=seq(1,nrow(data),1)`. – Dimitri Apr 06 '23 at 09:00
  • Thank you, that has solved the second error message! I still get the first error message about replacement rows. – kt99 Apr 06 '23 at 10:02
  • I don't know anything about `mids` objects, sorry. But maybe search fo NA's. The `Error in [<- data.frame(*tmp*, j, value = c(X, Y, : replacement has X rows, data has Y` message is often due to NA values. – Dimitri Apr 06 '23 at 10:15
  • 1
    Can you provide a reproducible example? https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – jrcalabrese Apr 06 '23 at 15:40
  • Please provide enough code so others can better understand or reproduce the problem. – Community Apr 07 '23 at 07:34

0 Answers0