Create an empty data.frame

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

    If you already have an existent data frame, let's say df that has the columns you want, then you can just create an empty data frame by removing all the rows:

    empty_df = df[FALSE,]
    

    Notice that df still contains the data, but empty_df doesn't.

    I found this question looking for how to create a new instance with empty rows, so I think it might be helpful for some people.

提交回复
热议问题