cheetahfly 发表于 2017-7-31 16:48
你把Hadley Wickham的几本著作熟读,就差不多啦。
- library(dplyr)
- library(stringr)
- a <- c(1,2,3,8)
- b <- c("2a","5","6a","4a")
- c <- c(4,8,9,0)
- d <- c("5b","6","10","6b")
- dat <- data.frame(a,b,c,d)
- #要求:把b中后缀带a的、d中后缀带b的观测剔除
- x = str_subset(dat$b, "a$")
- y = str_subset(dat$d, "b$")
- dat <- dat %>% filter(b %in% x) %>% filter(d %in% y)
复制代码大神我又来请教你了,你应该一看就知道我想问什么了。我能把b中后缀带a的、d中后缀带b的观测挑出来,但是只会保留,剔除的话各种尝试各种失败啊
别的方法还没试,就想问问用dplyr包怎么做?