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. 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.
Warning message:
In id == c(6, 8, 17) : longer object length is not a multiple of shorter object length
You should filter using %in%
instead of ==
.
DF_1 = DF %>%
filter(id %in% c(6,8,17))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.