Reputation: 2065
names(U1)
[1] "username" "review_count" "forum_posts" "age" "avg_interval"
[6] "avg_sim" "class"
So how do I create an empty data frame U1.RN that will have same columns as U1?
Upvotes: 37
Views: 36064
Reputation: 1528
For completeness. This resets an existing data frame to zero rows.
U1.RN <- U1
attributes(U1.RN)$row.names <- c()
# <0 rows> (or 0-length row.names)
Note that rownames() <- NULL
"deletes" the rownames and then fills them in with the default.
Upvotes: 0
Reputation: 794
Along the lines of df[0,]
you can also use a boolean mask which might make the code more readable:
df[FALSE,]
Upvotes: 12
Reputation: 2270
Using dplyr
, there are a few good options:
slice(U1, 0)
filter(U1, FALSE)
filter(U1, NA)
The slice
approach is probably clearest.
Upvotes: 8