I'm organizing some gatherings, and I've been storing the names and phone extensions in an R dataframe.
我正在组织一些聚会,我一直在R数据帧中存储名称和电话分机。
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
要仅邀请Yamazakis,我准备列表
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?
我如何准备一份排除Xaviers和Yamazakis的名单,但其中包括其他人?
Related questions:
- R grep: is there an AND operator?
- R — Logical grep on multiple variables within data frame
R grep:有一个AND运算符吗?
R - 数据帧内多个变量的逻辑grep
1 个解决方案
#1
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
#1
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