我有两个载体
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,但是,这并没有解决我的困境。
答案 0 :(得分:2)
另一种方法:
df1 <- c("a","b","c")
df2 <- c("1","2","3")
apply(expand.grid(df1, df2), 1, paste, collapse="")
答案 1 :(得分:0)
像这样:
paste0(rep(df1, length(df1)), rep(df2, length(df2)))
或者这个:
df_comb <- expand.grid(df1, df2)
paste0(df_comb$Var1, df_comb$Var2)
答案 2 :(得分:0)
您可以merge
:apply(merge(df1, df2), 1, function(row) paste(row[1], row[2], sep = ''))