[R] Paste problem when looping variable assignments

From: armstrwa <William.Armstrong_at_noaa.gov>
Date: Fri, 22 Apr 2011 10:45:51 -0700 (PDT)

Hi all,

I am attempting to run through a large set of data and sort events by the water year (1 Oct - 30 Sep) in which they occurred.

I have no problem doing this for each individual site I am looking at (so my problem is not with most of the code, just one minor thing), but when I try to loop it to do the same things for each site, I run into problems.

I think the root of my problem is that I am trying to switch the name of a variable for each iteration of the loop. I am using a paste function on the left side of a "<-" statement, which R doesn't seem to like. I am trying to create a variable for each site I am looking at (with the format "sitename_pdswy") that contains how many events occurred in a given year, which I want to use in further calculations. I keep getting the following error message:

Error in paste(pds_gagehandles[[i]], "_pdswy", sep = "") <- POTWY_cut :   could not find function "paste<-"

Does anyone know how I might be able to do this? It seems like the type of thing that must have a simple solution that I am just overlooking..

I have posted my entire code below, with the problematic line bolded and italicized.

Thank you very much for your help.


full code:

for(i in 1:length(pds_gagehandles)){
dates<-get(paste(pds_gagehandles[i],"_pds_rawd",sep="")) q<-get(paste(pds_gagehandles[i],"_pds_rawq",sep=""))

yr<-as.numeric(strftime(dates,format='%Y')) mo<-as.numeric(strftime(dates,format='%m')) len<-length(yr)

	for(n in 1:len){


partialpeakind<-which(round(q,2)>=round(pds_TD[i],2)) partialpeaksd<-dates[partialpeakind]

	for(q in 1:length(partialpeaksWY)){
	POTWY[[q]]<-sum(partialpeaksWY == wyrs[q])


write.table(pds_dropdates,file=paste(pds_gagehandles[i],"_dropdates.txt",sep="")) write.table(data.frame(wyrs,POTWY_cut),file=paste(pds_gagehandles[i],"_POTWY.txt",sep=""))

View this message in context: http://r.789695.n4.nabble.com/Paste-problem-when-looping-variable-assignments-tp3468414p3468414.html
Sent from the R help mailing list archive at Nabble.com.

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 22 Apr 2011 - 17:49:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 22 Apr 2011 - 18:00:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive