sapply paste before at beginning of string
Вопрос
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$"
Не связан с StackOverflow