[英]How to filter rows using tidyverse in r?
Thought it would be an easy task but is giving me quite a headache.认为这将是一项简单的任务,但让我很头疼。 I am trying to
filter
rows when a particular conditio
n is met, however, i am getting an error.我正在尝试在满足特定
conditio
时filter
行,但是,出现错误。 Below is a sample code下面是一个示例代码
library(tidyverse)
DF = data.frame(id = sample.int(20,20, replace = TRUE), A = runif(20, 100, 150), Dat = runif(20, 400,700))
DF_1 = DF %>% filter(id == c(6,8,17))
But the code give me below warning with a DF_1
data.frame
that has only data when id
is equal to 8 and 17 while it should be giving me a data.frame
for id
being equal to 6,8, and 17.但是代码给了我一个
DF_1
data.frame
警告,当id
等于 8 和 17 时它只有数据,而它应该给我一个data.frame
id
等于 6,8 和 17。
Warning message:
警告信息:
In id == c(6, 8, 17) : longer object length is not a multiple of shorter object length
在 id == c(6, 8, 17) 中:较长的对象长度不是较短对象长度的倍数
You should filter using %in%
instead of ==
.您应该使用
%in%
而不是==
过滤。
DF_1 = DF %>%
filter(id %in% c(6,8,17))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.