[英]na.omit not removing NA (data is numerical)
I have just merged two data frames and am trying to remove rows with a NA in the value column. 我刚刚合并了两个数据框,并试图删除值列中带有NA的行。 As of now I have..
截至目前我有......
t.dup.rights <- merge(dataframe1, dataframe2, by = "ID", all = T)
na.omit(tdup.rights$value)
The value column has either a 1 or NA. 值列具有1或NA。 I used
我用了
is.numeric(t.dup.rights$value)
to double check that r doesn't think it's a factor. 仔细检查r不认为这是一个因素。 After I run the na.omit function the data frame appears to remain unchanged.
运行na.omit函数后,数据框似乎保持不变。 I am working with a particularly large data set (200K obs).
我正在处理一个特别大的数据集(200K obs)。 I am also using the dplyr package.
我也在使用dplyr包。
You can use tidyr::drop_na
你可以使用
tidyr::drop_na
library(dplyr)
library(tidyr)
df <- data_frame(
x = sample(c(NA, 1, 2), 10, replace = TRUE),
y = sample(c(NA, 1, 2), 10, replace = TRUE)
)
df
#> # A tibble: 10 x 2
#> x y
#> <dbl> <dbl>
#> 1 NA NA
#> 2 1 2
#> 3 2 2
#> 4 NA 1
#> 5 2 NA
#> 6 1 NA
#> 7 NA NA
#> 8 2 2
#> 9 1 NA
#> 10 NA 2
drop_na(df, x)
#> # A tibble: 6 x 2
#> x y
#> <dbl> <dbl>
#> 1 1 2
#> 2 2 2
#> 3 2 NA
#> 4 1 NA
#> 5 2 2
#> 6 1 NA
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.