Re: [R] Data frames questions

From: X.H Chen <xchen_stat_at_hotmail.com>
Date: Sat 23 Sep 2006 - 22:16:13 GMT


>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"))

>2) Is there a way to reorder the variables in a data frame, e.g. When I go
>to write out a data frame using write.table or write.matrix, I want the
>output in a certain order...

df2<-as.data.frame(matrix(1:4,nrow=2,ncol=2),row.names=c("R3","R4")) df2<-df2[c(2,1),]

>3) How to I "append" to the bottom of a dataframe?

df2<-rbind(df2,c(5,6))

Xiaohui Chen

Dept. of Statistics
UBC, Canada

>From: Jonathan Greenberg <jgreenberg@arc.nasa.gov>
>To: R-help <r-help@stat.math.ethz.ch>
>Subject: [R] Data frames questions
>Date: Sat, 23 Sep 2006 14:54:00 -0700
>
>Hi there, couple of questions on data frames:
>
>1) Is there a way to build an empty data frame, containing nothing but the
>data frame variable names?
>2) Is there a way to reorder the variables in a data frame, e.g. When I go
>to write out a data frame using write.table or write.matrix, I want the
>output in a certain order...
>3) How to I "append" to the bottom of a dataframe?
>
>Thanks!
>
>--j
>
>--
>Jonathan A. Greenberg, PhD
>NRC Research Associate
>NASA Ames Research Center
>MS 242-4
>Moffett Field, CA 94035-1000
>Office: 650-604-5896
>Cell: 415-794-5043
>AIM: jgrn307
>MSN: jgrn307@hotmail.com
>
>______________________________________________
>R-help@stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun Sep 24 08:23:40 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 24 Sep 2006 - 15:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.