[R] Iterated Data Input/Output with Random Forests
johnzhou at fas.harvard.edu
johnzhou at fas.harvard.edu
Sun Jul 23 19:52:19 CEST 2006
While tempData[paste('pheno',i,sep='')] does give the appropriate column, when I
try to use that expression in the factor function:
factor(tempData[paste('pheno',i,sep='')]) I get
Error in sort(unique.default(x), na.last=TRUE : 'x' must be atomic.
Quoting jim holtman <jholtman at gmail.com>:
> For your last question of the 'paste', try
>
> tempdata[paste('pheno', i, sep='')]
>
>
>
> On 7/23/06, johnzhou at fas.harvard.edu <johnzhou at fas.harvard.edu> wrote:
> >
> > Hi,
> >
> > I am currently writing code to input a few thousand files, run them
> > through the
> > Random Forests package, and then output corresponding results.
> >
> > When I use the code below:
> >
> > zz<-textConnection("ex.lm.out", "w")
> > sink(zz)
> > tempData<-read.delim(paste("allSnps",1,"Phenotype.phn
> > ",sep=""),header=TRUE,sep=",",quote="\"",dec=".")
> > tempData[[1]]<-factor(tempData[[1]])
> > tempData.rf
> >
>
<-randomForest(tempData[[1]]~.,data=tempData,importance=TRUE,proximity=TRUE,outscale=TRUE,replace=TRUE)
> > tempData.rf
> > zz<-file(paste("ex",1,".data",sep=""), "w")
> > cat(ex.lm.out, sep="\n", file=zz)
> > sink()
> > close(zz)
> >
> > I am able to successfully input and output for one file. However, if I try
> > to
> > use a for loop or a while statement e.g.
> >
> > for(i in 1:2)
> > {
> > zz<-textConnection("ex.lm.out", "w")
> > sink(zz)
> > tempData<-read.delim(paste("allSnps",i,"Phenotype.phn
> > ",sep=""),header=TRUE,sep=",",quote="\"",dec=".")
> > tempData[[1]]<-factor(tempData[[1]])
> > tempData.rf
> >
>
<-randomForest(tempData[[1]]~.,data=tempData,importance=TRUE,proximity=TRUE,outscale=TRUE,replace=TRUE)
> > tempData.rf
> > zz<-file(paste("ex",i,".data",sep=""), "w")
> > cat(ex.lm.out, sep="\n", file=zz)
> > sink()
> > close(zz)
> > }
> >
> > I get no error statements but the output is blank. Without the for
> > statement,
> > setting i<-1 works fine.
> >
> > One other related question is that right now I am trying to gett the loop
> > to
> > work by using the paste() function with a variable (i). However, the paste
> > function returns a string.
> >
> > If I wanted to make a loop of
> >
> > tempData$pheno1
> > tempData$pheno2
> > tempData$pheno3
> > ...
> >
> > the paste() function will not work. Is there some other method to achieve
> > the
> > desired effect? Thank you in advance! I have only been working with R for
> > a few
> > days so please bear with my lack of knowledge!
> >
> > John Zhou
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem you are trying to solve?
>
More information about the R-help
mailing list