这是一个虚拟数据:
father<- c(1, 1, 1, 1, 1)
mother<- c(1, 1, 1, NA, NA)
children <- c(NA, NA, 2, 5, 2)
cousins <- c(NA, 5, 1, 1, 4)
dataset <- data.frame(father, mother, children, cousins)
dataset
father mother children cousins
1 1 NA NA
1 1 NA 5
1 1 2 1
1 NA 5 1
1 NA 2 4
Run Code Online (Sandbox Code Playgroud)
我想过滤这一行:
father mother children cousins
1 1 NA NA
Run Code Online (Sandbox Code Playgroud)
我可以这样做:
test <- dataset %>%
filter(father==1 & mother==1) %>%
filter (is.na(children)) %>%
filter …Run Code Online (Sandbox Code Playgroud) 我有以下数据框让我们称之为df
id type company
1 NA NA
2 NA ADM
3 North Alex
4 South NA
NA North BDA
6 NA CA
Run Code Online (Sandbox Code Playgroud)
我想只保留"类型"和"公司"栏中没有NA的记录
id type company
3 North Alex
NA North BDA
Run Code Online (Sandbox Code Playgroud)
我累了
df_non_na <- df[!is.na(df$company) || !is.na(df$type), ]
Run Code Online (Sandbox Code Playgroud)
但这没效果.
提前致谢