[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

#the loop is checking variance of rows, and cutting out rows with
#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


             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 
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)

#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



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