[R] Data frames questions

X.H Chen xchen_stat at hotmail.com
Sun Sep 24 00:16:13 CEST 2006


>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 at arc.nasa.gov>
>To: R-help <r-help at 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 at hotmail.com
>
>______________________________________________
>R-help at 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.



More information about the R-help mailing list