I have a data frame and a column with over 1.000.0000 values. I know that I need to take values from 1:30.000 then, 30.000:60.000 and so on, and cbind this parts, to get multiple columns out of the original one. How do I do that?
Asked
Active
Viewed 251 times
-2
-
So you have a data.frame of one column and want to end up with a data.frame of 1.000.000 rows. – s_baldur Jun 24 '19 at 08:26
-
You can create a matrix from a single column (vector) with wanted number of rows: `matrix(iris$Sepal.Length, 50)`. Here you *cbind* one column by 50. In the end you can create a data frame: `as.data.frame(matrix(iris$Sepal.Length, 50))` – pogibas Jun 24 '19 at 08:27
-
My data frame has multiple columns, but one of them, let's say data.frame$ID, is huge, and divide it in 50 equal parts, 1:30.000, 30.000:60.000 and so on.... now part 1:30.000 needs to become a column itself, and the columns that follows needs to be 30.000:60.000 .... – user11465312 Jun 24 '19 at 08:29
-
I will try that PoGibas thank you. Will check now :) – user11465312 Jun 24 '19 at 08:30
1 Answers
0
We can split
the column into a list
and cbind
n <- 30000
out <- do.call(cbind, split(df1$ID, as.integer(gl(nrow(df1), n, nrow(df1)))))
If the split
s are not of equal length, we can use cbind.fill
from rowr
library(rowr)
out <- do.call(cbind.fill, split(df1$ID, as.integer(gl(nrow(df1), n, nrow(df1)))))

akrun
- 874,273
- 37
- 540
- 662
-
-
-
@user11465312 IN that case change `df1` to `df`. In the comments above, you said `data.frame$ID`, so I was not sure about the object identifier – akrun Jun 24 '19 at 08:37
-
-
@user11465312 That is a memory issue. You may need to increase the memory – akrun Jun 24 '19 at 08:39