0

I'm organizing some gatherings, and I've been storing the names and phone extensions in an R dataframe.

names <- c("Adrian Xavier", "Berta Xavier",
           "Charles Yamazaki", "Daniela Yamazaki",
           "Edward Zachary", "Fiona Zachary")
phonex <- c(4739, 3894,
            7238, 7459,
            7573, 9457)
people <- data.frame("Name"=names, "PhoneX"=phonex)

To invite the Yamazakis only, I prepare the list by

only_y <- people[grep("Yamazaki", people$"Name"), ]

and to prepare a list that excludes the same set, I run:

exclude_y <- people[grep("Yamazaki", people$"Name", invert=TRUE), ]

How do I prepare a list that excludes both the Xaviers and the Yamazakis, but that includes everyone else?

Related questions:

Calaf
  • 10,113
  • 15
  • 57
  • 120

1 Answers1

2

Just use the or in your regular expression.

people[!grepl("Yamazaki|Xavier", people$Name), ]

            Name PhoneX
5 Edward Zachary   7573
6  Fiona Zachary   9457
erocoar
  • 5,723
  • 3
  • 23
  • 45