jeudi 9 février 2017

for i in a string vector in R

I'm new to R scripting and there's a task I'd like to accomplish. I have generated a string vector which is stored in a variable named iter. This vector contains the name of the samples we tested in the lab.

For each sample I'd like to do some statistical test and store them into variables for further use. I dont know the sintax of control structures in R but I'd like to do something like this (bash style):

for i in iter; do
$i<-subset(out,TestId=="i" & AddId=="Curve_F_Cor")
$i<-$i[,"mu.spline"]
$i.shapi<-shapiro.test(as.numeric($i.mu))
   if [ $i.shapi$p.value -gt 0.05 ]; then
       t.test_$i_mu<-t.test(as.numeric($i.mu),as.numeric(reference.mu), alternative = "less", conf.level = 0.95)
   fi
done

I have been googleing but there's not much related about for loop or if statement using string in R.

Thank you :)

Aucun commentaire:

Enregistrer un commentaire