[R] a combind problem with list

tedzzx zengzhenxing at gmail.com
Tue Oct 28 09:15:59 CET 2008


Hi all,

I came across a combinding promblem.
suppose I have got a list:
#we got three elements in this list and each elements is a dataframe
s<-lapply(1:3,funtion(i){data.frame(mean=numeric(),median=numeric())}) 
 
using the inside data in R:  a<-state.x77
f<-function(x){c(mean=mean(x),median=(x))}
g<-t(apply(a,2,f))
#g is a data frame 
# now I want to combind the first row of g with the first list element of s.
Note that the first elemment of #list g is data frame. Besides, these two
dataframe have the same column names.
s[[1]]<-rbind(s[[1]],g[1,])
The result is supposed to be a data frame with the column names: mean,
median , but actually I have got the wrong column names. 
Why?

Besides, in the function :f<-function(x){c(mean=mean(x),median=(x))}, why we
use c() here?
why not write the function like this:
f<-function(x){mean=mean(x)
median=(x)
}
I just copy this function.

Thanks advance

Ted


-- 
View this message in context: http://www.nabble.com/a-combind-problem-with-list-tp20202923p20202923.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list