Hello, what does this error message indicate and how do I avoid this? (sample code below) Thank you. -Tosh #read in the data table co<-read.table("co.txt",header=T,as.is=T) for (i in 1:3){ paste("logco",i, sep="")<-log(co$co[co$day==i]) } Gives the error: Error: Target of assignment expands to non-language object -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
The statement in your for loop doesn't make much sense. It's attempting to assign something to the function paste(). Instead, log(co$co[co$day==i]) should probably be in the argument list of paste() and the result should then be assigned to a character object, i.e. something like: sometxt[i] <- paste("logco",i,log(co$co[co$day==i], sep="") If you let us know what you're trying to do, we might be more help. Pierre "T. Hotchi" wrote:> > Hello, what does this error message indicate and how do I avoid this? > (sample code below) > > Thank you. > > -Tosh > > #read in the data table > co<-read.table("co.txt",header=T,as.is=T) > > for (i in 1:3){ > paste("logco",i, sep="")<-log(co$co[co$day==i]") > } > > Gives the error: > Error: Target of assignment expands to non-language object > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- ----------------------------------------------------------------- Pierre Kleiber Email: pkleiber at honlab.nmfs.hawaii.edu Fishery Biologist Tel: 808 983-5399/737-7544 NOAA FISHERIES - Honolulu Laboratory Fax: 808 983-2902 2570 Dole St., Honolulu, HI 96822-2396 ----------------------------------------------------------------- "God could have told Moses about galaxies and mitochondria and all. But behold... It was good enough for government work." ----------------------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Give assign a rev. "T. Hotchi" wrote:> > Hello, what does this error message indicate and how do I avoid this? > (sample code below) > > Thank you. > > -Tosh > > #read in the data table > co<-read.table("co.txt",header=T,as.is=T) > > for (i in 1:3){ > paste("logco",i, sep="")<-log(co$co[co$day==i])assign(paste("logco",i,sep=""),log(co$co[co$day==1]))> }Bob Murison -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, 18 Apr 2002, T. Hotchi wrote:> Hello, what does this error message indicate and how do I avoid this? > (sample code below) > > Thank you. > > -Tosh > > #read in the data table > co<-read.table("co.txt",header=T,as.is=T) > > for (i in 1:3){ > paste("logco",i, sep="")<-log(co$co[co$day==i]) > } > > Gives the error: > Error: Target of assignment expands to non-language objectAnother response pointed you to the assign function which is the way to do what you are trying to do. However assigning to global variables in a loop or function is often not a good idea. If you want to save a bunch of things and generate their names on the fly then a list is often a better approach. Replace your above code with something like: mylogs <- list() # create an empty list to put data into for (i in 1:3){ mylogs[[ paste("logco",i, sep="") ]] <- log(co$co[co$day==i]) } now you can access the results in several different ways: mylogs[["logco1"]] mylogs$logco1 or attach(mylogs) logco1 This approach generaly does what you want and keeps from creating to many top level global variables. It is also easier to dump one single list to a file for backup or tranfer than to do the same with all of your global variables. hope this helps, -- Greg Snow, PhD Office: 223A TMCB Department of Statistics Phone: (801) 378-7049 Brigham Young University Dept.: (801) 378-4505 Provo, UT 84602 email: gls at byu.edu -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._