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

Lothar Botelho-Machado r-help at botelho-machado.de
Tue Aug 8 13:51:48 CEST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Patrick Burns wrote:
> Chapter 1 of S Poetry might help you come to
> grips with data structures in R.
> 
> 
> Patrick Burns
> patrick at burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of S Poetry and "A Guide for the Unwilling S User")
> 
> Lothar Botelho-Machado wrote:
> 
>> Dear R mailing-list comunity!
>>
>>
>>
>> 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 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.
>>
>>
>>  
>>
> 


Thank you!

I was rather concentrated in finding something especially for "R" and
didn't search for "S" as well. I'll have a look in "S Poetry" now, It
seems like that's exactly the thing I was looking for, the last days!

Great!
 Lothar Rubusch
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFE2HrUHRf7N9c+X7sRAvEeAJwPQTjDm0qmtz15mWJIPEmF5atIzQCfa0kC
YyzgDhUMoeXdeJ4LzRHWTc4=
=MIq/
-----END PGP SIGNATURE-----



More information about the R-help mailing list