Remove columns from dataframe where some of values are NA

前端 未结 7 1372
小鲜肉
小鲜肉 2020-11-28 08:32

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           


        
7条回答
  •  渐次进展
    2020-11-28 09:10

    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()).

提交回复
热议问题