简体   繁体   中英

Combine vectors for factorial designs in R

I would like to create a table that combines multiple vectors in R.

vec1<-c("a", "b")
vec2<-seq(2,4)
vec3<-c("x", "y")

It should look like this:

vec1 vec2 vec3
a    2    x
a    2    y
a    3    x
a    3    y
a    4    x
a    4    y
b    2    x
b    2    y
b    3    x
b    3    y
b    4    x
b    4    y

I tried to use outer . It does what I want when I have two vectors, but not when I have more than two vectors.

更明确:

expand.grid(vec1, vec2, vec3)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM