Answers for "combine row for every element of vector r"

R
0

combine row for every element of vector r

# 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)
Posted by: Guest on January-27-2021

Browse Popular Code Answers by Language