Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
だから私はベクトルを持っています
lizt <- c("a","b","c") > lizt [1] "a" "b" "c"
sapplyを使用して、各要素の後に文字を貼り付けることができます
lizt2 <- sapply(lizt,paste0, "$", USE.NAMES=F) lizt2 [1] "a$" "b$" "c$"
さて、同様の関数を使用して各要素の前に文字を貼り付けるにはどうすればよいですか?
lizt3 [1] "^a$" "^b$" "^c$"
pasteベクトル化されてpaste0いるので、必要ありませんsapply
paste
paste0
sapply
paste0('^', lizt, '$') ## [1] "^a$" "^b$" "^c$"
mnel が示したように、ここで使用する必要はありませんがsapply、とにかく使用したい場合は、次のsapplyように使用する独自のカスタム関数を作成できます。
> sapply(lizt, function(x) paste0("^", x, "$"), USE.NAMES=FALSE) [1] "^a$" "^b$" "^c$"