After the standard cleanup procedure for missing data (na.omit()) I missing data (na.omit()) unable to add new variables to the data.frame . Error length mismatch. That is, despite the removal of these rows from the set, they are tacitly present in the data.frame , while the frame dimension after deletion is 855, and the new variable being added has a length of 970 (as in the original data set).

Is there a simple way out?

  • one
    Try tidyr::drop_na() But the reproducible example won't hurt at all - ikashnitsky

1 answer 1

According to the above description, everything is just the opposite. After completing na.omit, the data is NOT present in the set - initially there were 970, some were deleted there, 855 remained, and you are trying to attach a 970 vector to them. It is clear that there will be a mismatch of lengths. Exit - We first add a new column, then we run na.omit.

  • That's the question. The initial size of data.frame is 970. In theory, after deleting rows from NA, the size should have been reduced to 855, but the new vector being added automatically gets the length of the original data.frame. Plus, some functions (for example dataEllipse ()) swear for the presence of NA. - Aggle
  • Or something I do not understand, or? What does "new vector automatically get length ???". dataset <-na.omit (dataset) dataset dataset <-cbind (dataset, c (rep (1, nrow (dataset)))) - passant