Chu
Chu

Reputation: 17

replicate columns in R

Let's consider the data set iris.

>iris
        Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
    1            5.1         3.5          1.4         0.2     setosa
    2            4.9         3.0          1.4         0.2     setosa
    3            4.7         3.2          1.3         0.2     setosa

How can we replicate each of the COLUMNS of this data set 12 times?

Upvotes: 0

Views: 1590

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 389065

You could replicate the columns using rep and each parameter.

iris[rep(1:ncol(iris), each = 12)]

Upvotes: 1

Related Questions