vendredi 23 septembre 2016

Problems with an if statement

I have a complex matrix with several rows per individual. I create a script where I summarize different variables per individual. In order to do that, I first create a list with the new summarized variables in it. In order to get some of these variables I need to introduce if clases like the following:

this_iids_roh <- dat[class,]
my_list<-c("Froh"=(sum(this_iids_roh$KB)/2881033),
         "chr1"= if (this_iids_roh$CHR==1) {(sum(this_iids_roh$KB)/247249.719)*100}, 
         "chr2"= if (this_iids_roh$CHR==2) {(sum(this_iids_roh$KB)/242193.529)*100}, 
         "chr3"= if (this_iids_roh$CHR==3) {(sum(this_iids_roh$KB)/198295.559)*100})
return(my_list)
}

However when I do run this script (this is just a small part) I only get the "Froh" and "chr1" variables. I tried several things but I'm not being able to get other variables after "chr1". I hope you can help me!

Aucun commentaire:

Enregistrer un commentaire