I have a dataframe where some of the values are NA. I would like to remove these columns.
My data.frame looks like this
v1 v2
1 1 NA
2
A base R method related to the apply
answers is
Itun[!unlist(vapply(Itun, anyNA, logical(1)))]
v1
1 1
2 1
3 2
4 1
5 2
6 1
Here, vapply
is used as we are operating on a list, and, apply
, it does not coerce the object into a matrix. Also, since we know that the output will be logical vector of length 1, we can feed this to vapply
and potentially get a little speed boost. For the same reason, I used anyNA
instead of any(is.na())
.