假设我有一个向量:
tt <- c("test", "this" "function")
我该怎么做才能将其转换为:
>tt "test AS test", "this AS this", "function AS function"
我尝试了几次粘贴,但无法完全得到我想要的。
假设我有一个向量:
tt <- c("test", "this" "function")
我该怎么做才能将其转换为:
>tt "test AS test", "this AS this", "function AS function"
我尝试了几次粘贴,但无法完全得到我想要的。
paste
被矢量化:
> tt <- c("test", "this", "function")
> paste(tt,"AS",tt)
[1] "test AS test" "this AS this" "function AS function"
你会想要使用sapply
> sapply(tt, function(X) paste0(X, " AS ", X))
test this function
"test AS test" "this AS this" "function AS function"