How do I identify a string using a wildcard?
I've found glob2rx
, but I don't quite understand how to use it. I tried using the following code to pick the rows of the data frame that begin with the word blue
:
# make data frame
a <- data.frame( x = c('red','blue1','blue2', 'red2'))
# 1
result <- subset(a, x == glob2rx("blue*") )
# 2
test = ls(pattern = glob2rx("blue*"))
result2 <- subset(a, x == test )
# 3
result3 <- subset(a, x == pattern("blue*") )
However, neither of these worked. I'm not sure if I should be using a different function to try and do this.
See Question&Answers more detail:os