Create an empty data.frame

前端 未结 17 904
猫巷女王i
猫巷女王i 2020-11-22 16:06

I\'m trying to initialize a data.frame without any rows. Basically, I want to specify the data types for each column and name them, but not have any rows created as a result

17条回答
  •  无人及你
    2020-11-22 16:21

    I keep this function handy for whenever I need it, and change the column names and classes to suit the use case:

    make_df <- function() { data.frame(name=character(),
                         profile=character(),
                         sector=character(),
                         type=character(),
                         year_range=character(),
                         link=character(),
                         stringsAsFactors = F)
    }
    
    make_df()
    [1] name       profile    sector     type       year_range link      
    <0 rows> (or 0-length row.names)
    

提交回复
热议问题