How to copy an object structure (but not data)

Noob Question:

How to copy specifications of objects, but not data?

In my particular case, I have a data frame, and I need a different data frame with the same column classes, same column names, same number of rows, but without any data inside

I think I should already do this, but I do not: (

+8
r
source share
1 answer

You cannot have data and as many rows. If you do not want data, select the zero row. For example, with a set of cars dataset

 cars[0, ] 

or

 subset(cars, FALSE) 

If you need the same number of rows, set the data values ​​to NA .

 as.data.frame(lapply(cars, function(x) rep.int(NA, length(x)))) 
+19
source share

All Articles