I'm trying to remove NA values in the columns of a data frame and trying to cbind
the resulting vectors another data frame. Here's the code I'm using:
for (x in df_wide[4:8]) {
a <- df_wide[[x]][!is.na(df_wide[[x]])]
df <- cbind(df, a)
}
But I'm getting this error:
`Error in .subset2(x, i, exact = exact) : no such index at level 1`
I've also tried using apply
function, but I got the same error.
`Error in .subset2(x, i, exact = exact) : no such index at level 1`
function (x, i, exact)
if (is.matrix(i)) as.matrix(x)[[i]] else .subset2(x, i, exact = exact)
Can anyone please explain me why I'm getting this error and how can I fix it?
If you want to see the data frame, please refer to my previous question.
Thanks in advance.