说我有一个矢量:
tt <- c("test", "this" "function")
我可以做些什么来将其转换为:
>tt "test AS test", "this AS this", "function AS function"
我尝试了几次粘贴迭代但却无法得到我想要的东西。
答案 0 :(得分:8)
paste
已向量化:
> tt <- c("test", "this", "function")
> paste(tt,"AS",tt)
[1] "test AS test" "this AS this" "function AS function"
答案 1 :(得分:1)
您需要使用sapply
> sapply(tt, function(X) paste0(X, " AS ", X))
test this function
"test AS test" "this AS this" "function AS function"