[英]how to use ifelse function for all columns in r?
The following code works for 1 column (colname).以下代码适用于 1 列(列名)。 I want to use this function for all the columns.我想对所有列使用这个函数。 How to write the below code for all columns?如何为所有列编写以下代码?
data <- data %>%
mutate(colname = ifelse(colname == "NA",NA,colname)) %>%
filter(!is.na(colname))
I think you can use rowSums
to select rows that have no "NA"
in them.我认为您可以使用rowSums
来选择其中没有"NA"
行。
data <- data[rowSums(data == 'NA', na.rm = TRUE) == 0, ]
In dplyr
use if_all
-在dplyr
使用if_all
-
data <- data %>% filter(if_all(.fns = ~. != 'NA'))
我们可以使用base R
subset(data, !rowSums(data == 'NA', na.rm = TRUE))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.