如何使用dplyr从下面的数据集中选择Giovanni Bianchi和Luca Rossi?
NAME SURNAME COLOR ...
Giovanni Rossi Red
Giovanni Bianchi Red
Giovanni Bianchi Blue
Luca Rossi Blue
Luca Rossi Red
Giovanni Rossi Red
答案 0 :(得分:2)
您可以使用paste
创建全名,filter
为新变量的子集
library(dplyr)
filter(d,paste(NAME,SURNAME) %in% c("Giovanni Bianchi","Luca Rossi"))
NAME SURNAME COLOR
1 Giovanni Bianchi Red
2 Giovanni Bianchi Blue
3 Luca Rossi Blue
4 Luca Rossi Red
数据
d <- read.table(text="
NAME SURNAME COLOR
Giovanni Rossi Red
Giovanni Bianchi Red
Giovanni Bianchi Blue
Luca Rossi Blue
Luca Rossi Red
Giovanni Rossi Red ",head=TRUE,stringsAsFactors=FALSE)