[R] Output table from for loop
bmoran
bruce.moran at teagasc.ie
Wed Dec 7 16:39:22 CET 2011
Hi, this might be basic but can't get it to work and it is hampering my R
usage:
#the loop is checking variance of rows, and cutting out rows with
var>numVec[i]
#I define outMat as object names I want to output to (does this make sense?
how else
#can I define sequential numbered output?)
#numVec is numbers I use in the loop
head(Counts)
AN1 AN2 AN3 AN4 var
GENE1 99 0 6 0 2360
GENE2 183 136 137 160 496
GENE3 301 199 233 187 1856
outMat<-paste("NewCounts", 1:5, sep="_") #names of
numVec<-c(100,200,500,1000,1500)
cutGenes<-function(x) {
for (i in 1:5) {
keep<- Counts$var<numVec[i] #gives logical vector
keep<-Counts[keep=="TRUE",] #apply logical vector to count data (table)
outMat[i]<-keep
}
}
#this all works fine if I define 'outMat[i]' as 'outMat' but then I can't
use the loop! The loop seems to make #outMat[i] take the i element of 'keep'
and only stores this.
#Help much appreciated, sorry if it is VERY basic, just a head scratcher for
me.
Thanks,
Bruce.
--
View this message in context: http://r.789695.n4.nabble.com/Output-table-from-for-loop-tp4169386p4169386.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list