Create an empty data.frame

前端 未结 17 938
猫巷女王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:33

    Say your column names are dynamic, you can create an empty row-named matrix and transform it to a data frame.

    nms <- sample(LETTERS,sample(1:10))
    as.data.frame(t(matrix(nrow=length(nms),ncol=0,dimnames=list(nms))))
    

提交回复
热议问题