[R] Data frames questions

BXC (Bendix Carstensen) bxc at steno.dk
Sun Sep 24 13:14:51 CEST 2006


> -----Original Message-----
> From: X.H Chen [mailto:xchen_stat at hotmail.com] 
> Sent: Sunday, September 24, 2006 12:16 AM
> To: jgreenberg at arc.nasa.gov; r-help at stat.math.ethz.ch
> Subject: Re: [R] Data frames questions
> 
> 
> >1) Is there a way to build an empty data frame, containing 
> nothing but 
> >the data frame variable names?
> 
> Yes, you can do it one way as followings:
> 
> df1<-as.data.frame(matrix(nrow=2,ncol=2),row.names=c("R1","R2"))

This results in a dataframe with two rows and two columns NA in it.
In order to build an empty dataframe one you could use:

df1 <- data.frame( X1=1, x2=3, l1=TRUE, d3=as.Date("2003-07-14")
)[NULL,]
str( df1 )

The key is the "NULL" for the rows, it removes the data but keeps the
content.

Best,
Bendix
----------------------
Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Niels Steensens Vej 2
DK-2820 Gentofte
Denmark
tel: +45 44 43 87 38
mob: +45 30 75 87 38
fax: +45 44 43 07 06
bxc at steno.dk
www.biostat.ku.dk/~bxc
----------------------
 
(snip)



More information about the R-help mailing list