I want to extract a specific word from a named vector having set of two words.
freq= c(23,34,45,21)
names(freq) = c("good boy", "bad boy","good car","car good")
freq
I want all those words starting with good. The following works but i want to pass good in a variable t and then extract it by passing that variable but it's not working. How to tell r that t is a variable and not a character in itself
# it works
freq[grep("^good",names(freq))]
# passing in a variable
t <- "good"
freq[grep("^t",names(freq))]