user10297843
user10297843

Reputation:

What's a concise way of making a data frame with many multiples of the same vector as its columns?

I'm making a data frame out of vector1 and 25 multiples of vector2, by doing the following:


df1 <- data.frame(vector1,
vector2, vector2, vector2, vector2, vector2,
vector2, vector2, vector2, vector2, vector2,
vector2, vector2, vector2, vector2, vector2,
vector2, vector2, vector2, vector2, vector2,
vector2, vector2, vector2, vector2, vector2)

Is there a more concise way of coding this?

Upvotes: 0

Views: 37

Answers (2)

Ronak Shah
Ronak Shah

Reputation: 388982

You can use replicate :

df1 <- cbind.data.frame(vector1, replicate(25, vector2))

Upvotes: 1

ThomasIsCoding
ThomasIsCoding

Reputation: 101335

Try the code below

data.frame(c(list(vector1),rep(list(vector2),25)))

Upvotes: 1

Related Questions