Initializing data.frames() [duplicate]
Is there a quick way to initialize an empty data frame? If you know what the dimensions will be? For example:
Suppose I would like a blank data frame that has 100 rows and 10:
x <- data.frame(1:100,2,3,4,5,6,7,8,9,10)
dim(x) ## that's right
But suppose I want something like 300 columns? How do I quickly initialize columns in a data.frame?
x <- data.frame(1:100,2,3,4,5 ....) ## *cries*
> df <- data.frame(matrix(ncol = 300, nrow = 100))
> dim(df)
[1] 100 300
I always just convert a matrix:
x <- as.data.frame(matrix(nrow = 100, ncol = 10))
精彩评论