[R] How to convert list elements to data.frames or vectors?

Date: Tue 08 Aug 2006 - 20:59:50 EST

I'm currently trying to implement an R method. I have two sets of data that I convert into a data.frame each. These data.frames I'd like to append to a list:

# generate a list

listTable<-list()

# add one set of data
x<-1000 ;y<-1 ;listTable[[length(listTable) + 1]] <- data.frame(matrix(rnorm(x*y), nrow=y)); rm(x); rm(y)

# add another set of data (same command)
x<-1000 ;y<-1 ;listTable[[length(listTable) + 1]] <- data.frame(matrix(rnorm(x*y), nrow=y)); rm(x); rm(y)

My objective is to performed some hypothesis tests on the data. To test if that works out correctly, I tried first using an unpaired t-test (therfore the data.frames consist only of one row each in the example).

# alternative, var.equal and conf.level shall
# be arguments of my method as well (alternative="two.sided",
# var.equal=TRUE, conf.level=0.95)

t.test(listTable[[1]][1,], listTable[[2]][1,], alternative=alternative, paired=FALSE, var.equal=var.equal, conf.level=conf.level)

And an F-test, throwing an error, like there were not enough observations in the x vector of the test's input.

# The F-test (ratio=1, alternative="two.sided", conf.level=0.95)
var.test(listTable[[1]][1,], listTable[[2]][1,], ratio=ratio, alternative=alternative, conf.level=conf.level)

I figured out, those tests work perfectly, using vectors instead of my list elements with the same argument values, hence there should be no problem with the parameters, I guess.

So, my problems would be the list elements like "listTable[[1]][1,]". They are no vectors but "list"s themselves containing each only one element?! I tried several things without any success to change that. I need to have a list like structure and couldn't find a way how to convert the list elements back to data.frames or vectors.

Thus I now have a bunch of basic questions on R:

1. If I put a data.frame into a list, how can I get it back as data.frame?
2. How can I get a single row of a data.frame, stored in a list, as vector and not as list of elements?
3. Is a "list" at all the correct structure for my deeds?
4. Why is this only a problem for the F-test and it seems to be no problem for the t-test?

Regards and TIA,
Lothar Rubusch

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 Tue Aug 08 21:07:19 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 Tue 08 Aug 2006 - 22:17:36 EST.

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