[R] loop through columns in S4 objects

francy francy.casalino at gmail.com
Thu Nov 24 18:52:05 CET 2011

Dear experts,

I am trying to perform an association using snpStats.
I have a snp matrix called 'plink' which contains my genotype data (as
a list of $genotypes, $map, $fam), and a phenotype data frame which
contains the outcomes (outcome1, outcome2,...) I would like to
associate with the genotype.
My question is, how do I loop through the outcomes? This type of data
seems different from all the others and I am having trouble
manipulating it, so I would also be grateful if you have suggestions
of some tutorials that can help me understand how to do this and other
manipulations such as subsetting the snp.matrix data for example.

This is what I have tried for the loop:

 rhs <- function(x) {
 x<- snp.rhs.tests(x, family="gaussian", data=phenotype,
 res_ <- apply(phenotype,2,rhs)

Error in x$terms : $ operator is invalid for atomic vectors

Then I tried this:

 for (cov in names(phenotype)) {
family="gaussian",data=phenotype, snp.data=snp.matrix$genotype)
Error in eval(expr, envir, enclos) : object 'outcome1' not found

Thank you as usual for your help!

View this message in context: http://r.789695.n4.nabble.com/loop-through-columns-in-S4-objects-tp4104836p4104836.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list