📜  为向量的每个元素组合行 - R 编程语言代码示例

📅  最后修改于: 2022-03-11 14:51:59.032000             🧑  作者: Mango

代码示例1
# Do this for vectors
v1 <- 1:2
v2 <- 3:4
expand.grid(v1, v2)
#  Var1 Var2
#1    1    3
#2    2    3
#3    1    4
#4    2    4

# Use merge for dataframes
df1 <- data.frame(a = 1:2, b=3:4)
df2 <- data.frame(cat = 5:6, dog = c("a","b"))
merge(df1, df2)