Hi all, I have attached the function file (revisedfunction) and the list of station IDs (StationIDs) in .pdf format. I have written a function to perform various operations on the station IDs in two groups. The first 6 station IDs require one less step than the remaining 68 station IDs. The file referenced at the beginning of the function is the file containing the StationIDs.> file "/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/calibration/example_setofstationsassociatedtosamegage.csv"> xynowget <- xygetN(file, hasHeader = TRUE, separator =",")Error in is.data.frame(x) : object 'Sample' not found Can you assist me in fixing the attached function file? Thank-you. Irucka Embry <span id=m2wTl><p><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">_______________________________________________________________<BR>Get the Free email that has everyone talking at <a href=http://www.mail2world.com target=new>http://www.mail2world.com</a><br> <font color=#999999>Unlimited Email Storage – POP3 – Calendar – SMS – Translator – Much More!</font></font></span>
David Winsemius
2013-Jan-15 01:46 UTC
[R] error in for loop in function (object not found)
Nothing attached. Please read the Webpage link and the Posting Guide more thoroughly. -- David. On Jan 14, 2013, at 5:31 PM, Irucka Embry wrote:> Hi all, I have attached the function file (revisedfunction) and the list > of station IDs (StationIDs) in .pdf format. > > I have written a function to perform various operations on the station > IDs in two groups. The first 6 station IDs require one less step than > the remaining 68 station IDs. The file referenced at the beginning of > the function is the file containing the StationIDs. > >> file > "/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca > libration/example_setofstationsassociatedtosamegage.csv" >> xynowget <- xygetN(file, hasHeader = TRUE, separator =",") > Error in is.data.frame(x) : object 'Sample' not found > > Can you assist me in fixing the attached function file? > > Thank-you. > > Irucka Embry >snip> > R-help at r-project.org 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.David Winsemius Alameda, CA, USA
Hi David, thanks for letting me know about the missing attachments.
This is the code for the function:
xygetN <- function(file, hasHeader = TRUE, separator = ",")
{
totalPath <- paste(file, sep = "")
tmp <- read.csv(totalPath, header = hasHeader, sep = separator,
fill = TRUE, comment.char = "#", as.is = TRUE, stringsAsFactors =
FALSE)
retval <- as.data.frame(tmp, stringsAsFactors = FALSE)
if (ncol(retval) == 2) {
names(retval) <- c("x", "y")
}
else if (ncol(retval) == 3) {
names(retval) <- c("x", "y", "lat_00600")
}
else if (ncol(retval) == 4) {
names(retval) <- c("x", "y", "lat_00600",
"lon_00600")
}
retval$y <- as.numeric(retval$y)
write.csv(Sample, file
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/example_setofstationsassociatedtosamegages.csv")
x <- retval[,1]
y <- retval[,2]
filenwissample <-
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/da
ta/Sample/nwis_wqdata_sc_n.csv"
for(i in seq(along=x[1:6])) {
Sample <- getSampleDataFromFilecustom(filenwissample, hasHeader = TRUE,
separator =",")
Sample <- subset(Sample,station_id==i)
Sample <- subset(Sample, select=c(date, remark, value))
write.csv(Sample, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/da
ta/SampleOutputFromNWIS/.nitrogen"))
filesnwis <-
list.files(pattern="/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer
-2012-Work/EGRET/data/SampleOutputFromNWIS/.nitrogen$")
for(l in seq(along=filesnwis)) {
Sample <- getCustomSampleDataFromFile(filesnwis[l], hasHeader = TRUE,
separator =",")
#getJulian("2000-10-01")
Sample <- subset(Sample,Julian>=55060)
#getJulian("2004-09-30")
Sample <- subset(Sample,Julian<=56520)
Sample<-removeDuplicates(Sample)
summary(Sample)
length(Sample$Date)
}
fileinfoN
<-"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/
data/Info/info_n.csv"
INFO<- getMetaDataFromFile(fileinfoN)
for(g in seq(along=filesnwis)) {
INFO<- subset(INFO,site.no=="g")
}
filesDV <-
list.files(pattern="/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer
-2012-Work/EGRET/data/DVfromNWIS/DVfromNWIS_pooledforallMRB2sites/.rdb.g
z$")
for(m in seq(along=y)) {
for(k in seq(along=filesDV)) {
Daily <- getDailyDataFromFileCustom(filesDV[k])
#getJulian("2000-10-01")
Daily <- subset(Daily,Julian>=55060)
#getJulian("2004-09-30")
Daily <- subset(Daily,Julian<=56520)
summary(Daily)
Sample<-mergeReport()
}
}
modelEstimation(localDaily = Daily,localSample = Sample, localINFO INFO,
windowY=10, windowQ=2, windowS=0.5,minNumObs=10,minNumUncen=10,
env=parent.frame())
INFO<-setPA(window = 4)
annualSeries<-makeAnnualSeries()
AnnualResults<-setupYears()
AnnualResults
tableResults(localAnnualResults = AnnualResults, localINFO = INFO, qUnit
= 1, fluxUnit = 13)
yearPoints<-c(2001,2002,2003,2004)
tableChange(localAnnualResults = AnnualResults, localINFO = INFO,
fluxUnit = 13, yearPoints)
AnnualResults<- setupYears(paLong = 3, paStart = 10, localDaily = Daily)
yield <- AnnualResults$Flux/INFO$drainSqKm
write.table(INFO, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
write.table(AnnualResults, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
write.table(yield, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
AnnualResults<- setupYears(paLong = 3, paStart = 1, localDaily = Daily)
yield <- AnnualResults$Flux/INFO$drainSqKm
write.table(AnnualResults, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
write.table(yield, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
AnnualResults<- setupYears(paLong = 3, paStart = 4, localDaily = Daily)
yield <- AnnualResults$Flux/INFO$drainSqKm
write.table(AnnualResults, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
write.table(yield, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
AnnualResults<- setupYears(paLong = 3, paStart = 7, localDaily = Daily)
yield <- AnnualResults$Flux/INFO$drainSqKm
write.table(AnnualResults, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
write.table(yield, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
}
filesstoretsample <-
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/da
ta/STORET/storetdata_SC/joinedstoretother_wqdata_sc.csv"
Sample <- getSampleDataFromFilecustom(filesstoretsample, hasHeader TRUE,
separator =",")
for(h in seq(along=x[7:74])) {
for(p in seq(along=y)){
Sample <- subset(Sample,station_id=="h")
Sample <- subset(Sample, select=c(date, remark, value))
write.csv(Sample, file=paste(h,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/da
ta/SampleOutputFromNWIS/.nitrogen"))
filesstoret <-
list.files(pattern="/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer
-2012-Work/EGRET/data/SampleOutputFromNWIS/.nitrogen$")
for(v in seq(along=filesstoret)) {
Sample <- getCustomSampleDataFromFile(filesstoret[v], hasHeader = TRUE,
separator =",")
#getJulian("2000-10-01")
Sample <- subset(Sample,Julian>=55060)
#getJulian("2004-09-30")
Sample <- subset(Sample,Julian<=56520)
Sample<-removeDuplicates(Sample)
summary(Sample)
length(Sample$Date)
}
fileinfoN
<-"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/
data/Info/info_n.csv"
INFO<- getMetaDataFromFile(fileinfoN)
for(d in seq(along=filesstoret)) {
INFO<- subset(INFO,site.no=="d")
}
const = INFO$drainSqKm/INFO$drainSqKmFlow
filesDV <-
list.files(pattern="/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer
-2012-Work/EGRET/data/DVfromNWIS/DVfromNWIS_pooledforallMRB2sites/.rdb.g
z$")
for(a in seq(along=y)) {
for(c in seq(along=filesDV)) {
Daily <- getDailyDataFromFileCustom(filesDV[c])
#getJulian("2000-10-01")
Daily <- subset(Daily,Julian>=55060)
#getJulian("2004-09-30")
Daily <- subset(Daily,Julian<=56520)
DailyModeled <- data.frame(Date=Daily$Date)
DailyModeled$Q <- Daily$Q*INFO$drainSqKmFlow
DailyModeled <- getPreLoadedDailyData(DailyModeled, qUnit 1,interactive =
TRUE)
Daily <- DailyModeled
summary(Daily)
Sample<-mergeReport()
}
}
modelEstimation(localDaily = Daily,localSample = Sample, localINFO INFO,
windowY=10, windowQ=2, windowS=0.5,minNumObs=10,minNumUncen=10,
env=parent.frame())
INFO<-setPA(window = 4)
annualSeries<-makeAnnualSeries()
AnnualResults<-setupYears()
AnnualResults
tableResults(localAnnualResults = AnnualResults, localINFO = INFO, qUnit
= 1, fluxUnit = 13)
yearPoints<-c(2001,2002,2003,2004)
tableChange(localAnnualResults = AnnualResults, localINFO = INFO,
fluxUnit = 13, yearPoints)
AnnualResults<- setupYears(paLong = 3, paStart = 10, localDaily = Daily)
yield <- AnnualResults$Flux/INFO$drainSqKm
write.table(INFO, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
write.table(AnnualResults, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
write.table(yield, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
AnnualResults<- setupYears(paLong = 3, paStart = 1, localDaily = Daily)
yield <- AnnualResults$Flux/INFO$drainSqKm
write.table(AnnualResults, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
write.table(yield, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
AnnualResults<- setupYears(paLong = 3, paStart = 4, localDaily = Daily)
yield <- AnnualResults$Flux/INFO$drainSqKm
write.table(AnnualResults, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
write.table(yield, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
AnnualResults<- setupYears(paLong = 3, paStart = 7, localDaily = Daily)
yield <- AnnualResults$Flux/INFO$drainSqKm
write.table(AnnualResults, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")
write.table(yield, file=paste(i ,
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca
libration/Calibration_Results/.AnnualResults"), append=T,col.names= NA,
sep = ",")}
}
}
Thank-you.
Irucka Embry
<-----Original Message-----> >From: David Winsemius [dwinsemius@comcast.net]
>Sent: 1/14/2013 7:46:52 PM
>To: iruckaE@mail2world.com
>Cc: r-help@r-project.org
>Subject: Re: [R] error in for loop in function (object not found)
>
>Nothing attached. Please read the Webpage link and the Posting Guide
more>thoroughly.
>
>--
>David.
>On Jan 14, 2013, at 5:31 PM, Irucka Embry wrote:
>
>> Hi all, I have attached the function file (revisedfunction) and the
list>> of station IDs (StationIDs) in .pdf format.
>>
>> I have written a function to perform various operations on the
station>> IDs in two groups. The first 6 station IDs require one less step than
>> the remaining 68 station IDs. The file referenced at the beginning of
>> the function is the file containing the StationIDs.
>>
>>> file >>
"/home/ie/IE2/Documents/USGS-2012-Work/SPARROW-Summer-2012-Work/EGRET/ca>> libration/example_setofstationsassociatedtosamegage.csv"
>>> xynowget <- xygetN(file, hasHeader = TRUE, separator
=",")
>> Error in is.data.frame(x) : object 'Sample' not found
>>
>> Can you assist me in fixing the attached function file?
>>
>> Thank-you.
>>
>> Irucka Embry
>>
>snip
>>
>> R-help@r-project.org 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.
>
>David Winsemius
>Alameda, CA, USA
>
>.
>
<span id=m2wTl><p><font face="Arial, Helvetica,
sans-serif" size="2"
style="font-size:13.5px">_______________________________________________________________<BR>Get
the Free email that has everyone talking at <a href=http://www.mail2world.com
target=new>http://www.mail2world.com</a><br> <font
color=#999999>Unlimited Email Storage – POP3 – Calendar
– SMS – Translator – Much
More!</font></font></span>
[[alternative HTML version deleted]]