R define dimensions of empty data frame

前端 未结 11 1158
清歌不尽
清歌不尽 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:15

    If only the column names are available like :

    cnms <- c("Nam1","Nam2","Nam3")
    

    To create an empty data frame with the above variable names, first create a data.frame object:

    emptydf <- data.frame()
    

    Now call zeroth element of every column, thus creating an empty data frame with the given variable names:

    for( i in 1:length(cnms)){
         emptydf[0,eval(cnms[i])]
     }
    

提交回复
热议问题