我有两个向量粘贴两种单独载体的所有组合中的R
df1 <- c("a","b","c")
df2 <- c("1","2","3")
# expected output
# a1 a2 a3 b1 b2 b3 c1 c2 c3
我见过Paste all combinations of a vector in R,但是,这并没有解决我的困境。
我有两个向量粘贴两种单独载体的所有组合中的R
df1 <- c("a","b","c")
df2 <- c("1","2","3")
# expected output
# a1 a2 a3 b1 b2 b3 c1 c2 c3
我见过Paste all combinations of a vector in R,但是,这并没有解决我的困境。
另一种方法:
df1 <- c("a","b","c")
df2 <- c("1","2","3")
apply(expand.grid(df1, df2), 1, paste, collapse="")
或简单的'do.call(paste0,expand.grid(df1,df2))' – Sotos
像这样:
paste0(rep(df1, length(df1)), rep(df2, length(df2)))
或者这样:
df_comb <- expand.grid(df1, df2)
paste0(df_comb$Var1, df_comb$Var2)
您可以merge
:apply(merge(df1, df2), 1, function(row) paste(row[1], row[2], sep = ''))
尝试:'as.vector(T (外(C( “一”,” b),c),c(1,2,3),'paste0')))' – aichao