How to copy an object's structure (but not the data)

Viewed 16704

How do I copy an object's specifications, but not the data?

In my specific case I have a data frame and I want another data frame with the same column classes, the same column names, the same number of rows but without any data inside.

2 Answers

Or a 2-step version

 new.df <- cars
 new.df[] <- NA
Related