在 R 中复制列
replicate columns in R
让我们考虑数据集 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
我们如何将这个数据集的每个列复制 12 次?
您可以使用 rep
和 each
参数复制列。
iris[rep(1:ncol(iris), each = 12)]
让我们考虑数据集 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
我们如何将这个数据集的每个列复制 12 次?
您可以使用 rep
和 each
参数复制列。
iris[rep(1:ncol(iris), each = 12)]