So I have a vector
lizt <- c("a","b","c")
> lizt
[1] "a" "b" "c"
and I can use sapply to paste characters after each element
lizt2 <- sapply(lizt,paste0, "$", USE.NAMES=F)
lizt2
[1] "a$" "b$" "c$"
now, how do I use a similar function to paste characters before each element, so I get
lizt3
[1] "^a$" "^b$" "^c$"
paste
and paste0
are vectorized, so you don't need sapply
paste0('^', lizt, '$')
## [1] "^a$" "^b$" "^c$"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With