Reputation: 43
I have a vector of strings, for example a list of states:
USstates<-rownames(USArrests)
I would like to remove some States from the vector using a rule. For instance, States that contains a double n in the name: Pennsylvanya, Tennessee, Connecticut, Minnesota
How do I go about it?
Upvotes: 0
Views: 42
Reputation: 521053
You may try:
USstates_nn <- USstates[!grepl("nn", USstates)]
Upvotes: 2
Reputation: 887048
We may use grep
with invert
as TRUE
USstates_nn <- USstates[grep("nn", USstates, invert = TRUE)]
Upvotes: 1