this question has answer here:
- create empty data.frame 13 answers
here's hack create empty data frame no rows , no columns:
iris[false, false] #> data frame 0 columns , 0 rows
smarter-looking code creates spurious column:
x <- list(null) class(x) <- c("data.frame") attr(x, "row.names") <- integer(0) str(x) #> 'data.frame': 0 obs. of 1 variable: #> $ : null
is there non-hack alternative?
the reason create such thing satisfy function can handle empty data frames not nulls.
this different similar questions because having no columns no rows.
df <- data.frame() str(df) 'data.frame': 0 obs. of 0 variables