Create a data.frame with m columns and 2 rows

前端 未结 2 1053
逝去的感伤
逝去的感伤 2021-02-01 13:56

I would like to create a data.frame in R with m (a variable) number of columns (for example 30), and 2 rows and fill all the values in the data.frame initially with 0\'s. It see

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 14:54

    Does m really need to be a data.frame() or will a matrix() suffice?

    m <- matrix(0, ncol = 30, nrow = 2)
    

    You can wrap a data.frame() around that if you need to:

    m <- data.frame(m)
    

    or all in one line: m <- data.frame(matrix(0, ncol = 30, nrow = 2))

提交回复
热议问题