Hi all,
  My problem may be related with the list manipulations. See below.
#example data
 a<-list()
 a[[1]]<-data.frame(matrix(c(1:4),ncol=2));
a[[2]]<-data.frame(matrix(c(5:8),ncol=2))
  I can use a[[1]]$X1,a[[1]]$X2,a[[2]]$X1,a[[2]]$X2 to use the corresponding
variables. But what i need to do is to use function parameters to specify
the variable names. The variable names will be different for various
dataset, so i need a common place to indicate it.
  Something like,
b<-function(var1=X1,var2=X2) {
 for (n in 1:2) {
  paste("a", "[[",n, "]]","$","var1", sep="")
  paste("a", "[[",n, "]]","$","var2", sep="")
  }
}
 b(var1=X1,var2=X2) will have the same effect
as a[[1]]$X1,a[[1]]$X2,a[[2]]$X1,a[[2]]$X2. Unfortunately, it does not
work.
 Anybody can give me some suggestions on this? Hope it is clear for this
question.
 Thanks a lot.
P.S.
> a
[[1]]
  X1 X2
1  1  3
2  2  4
[[2]]
  X1 X2
1  5  7
2  6  8


-----------------
Jane Chang
Queen's

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.

Reply via email to