开发者

Initializing data.frames() [duplicate]

开发者 https://www.devze.com 2023-02-07 20:00 出处:网络
This question already has answers here: How to开发者_如何转开发 initialize empty data frame (lot of columns at the same time) in R
This question already has answers here: How to开发者_如何转开发 initialize empty data frame (lot of columns at the same time) in R (2 answers) Closed 6 years ago.

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))
0

精彩评论

暂无评论...
验证码 换一张
取 消