Efficient method to subset drop rows with NA values in R

后端 未结 3 1980
一整个雨季
一整个雨季 2021-02-03 12:51

Background Before running a stepwise model selection, I need to remove missing values for any of my model terms. With quite a few terms in my model, there are t

3条回答
  •  清酒与你
    2021-02-03 13:34

    Let dat be a data frame and cols a vector of column names or column numbers of interest. Then you can use

    dat[!rowSums(is.na(dat[cols])), ]
    

    to exclude all rows with at least one NA.

提交回复
热议问题