我的资料如下所示:
library(tidyverse) df <- tribble( ~a, ~b, ~c, 1, 2, 3, 1, NA, 3, NA, 2, 3 )我可以删除所有 NA 观察与 drop_na():
I can remove all NA observations with drop_na():
df %>% drop_na()或删除单列中的所有 NA 观察值( a )
Or remove all NA observations in a single column (a for example):
df %>% drop_na(a)为什么我不能使用常规的!= 过滤管?
Why can't I just use a regular != filter pipe?
df %>% filter(a != NA)为什么我们必须使用tidyr中的特殊函数来删除NAs?
Why do we have to use a special function from tidyr to remove NAs?
推荐答案从@Ben Bolker:
From @Ben Bolker:
他没有与dplyr :: filter()
[T]his has nothing specifically to do with dplyr::filter()
从@Marat Talipov:
From @Marat Talipov:
[NA]与NA的比较,包括NA == NA,将返回NA
[A]ny comparison with NA, including NA==NA, will return NA
从相关答案 by @ farnsy:
From a related answer by @farnsy:
==操作符不会像你所期望的那样对待NA。
The == operator does not treat NA's as you would expect it to.
认为NA意思是我不知道那里是什么。正确答案到3> NA显然是NA,因为我们不知道缺失值是否大于3。那么NA = NA是一样的。他们是两个缺失的值,但真正的值可能是完全不同的,所以正确的答案是我不知道。
Think of NA as meaning "I don't know what's there". The correct answer to 3 > NA is obviously NA because we don't know if the missing value is larger than 3 or not. Well, it's the same for NA == NA. They are both missing values but the true values could be quite different, so the correct answer is "I don't know."
R不知道你在分析中正在做什么,所以代替可能引入后来最终被发布的错误令人尴尬,不允许比较运算符认为NA 是一个值。
R doesn't know what you are doing in your analysis, so instead of potentially introducing bugs that would later end up being published an embarrassing you, it doesn't allow comparison operators to think NA is a value.
更多推荐
使用dplyr :: filter()删除NA观察
发布评论