-5

How can I select Giovanni Bianchi and Luca Rossi from the dataset below using dplyr?

NAME          SURNAME   COLOR   ...
Giovanni      Rossi     Red 
Giovanni      Bianchi   Red 
Giovanni      Bianchi   Blue 
Luca          Rossi     Blue
Luca          Rossi     Red
Giovanni      Rossi     Red 
Spigonico
  • 137
  • 1
  • 10

1 Answers1

2

You could use paste to create the full name and filter to subset on that new variable

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

Data

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)    
scoa
  • 19,359
  • 5
  • 65
  • 80