R define dimensions of empty data frame

前端 未结 11 1155
清歌不尽
清歌不尽 2020-12-12 21:34

I am trying to collect some data from multiple subsets of a data set and need to create a data frame to collect the results. My problem is don\'t know how to create an empt

11条回答
  •  悲&欢浪女
    2020-12-12 22:34

    Would a dataframe of NAs work? something like:

    data.frame(matrix(NA, nrow = 2, ncol = 3))

    if you need to be more specific about the data type then may prefer: NA_integer_, NA_real_, NA_complex_, or NA_character_ instead of just NA which is logical

    Something else that may be more specific that the NAs is:

    data.frame(matrix(vector(mode = 'numeric',length = 6), nrow = 2, ncol = 3))

    where the mode can be of any type. See ?vector

提交回复
热议问题