> > library(RODBC) > library(HYDAT) > You will need to install HYDAT (the zip file) from > http://www.geog.ubc.ca/~rdmoore/Rcode.htm > > Below is my current code - which works. The [[]] is the way i am accessing > the columns from the data frame. > > thanks again for all your help!!!! > > # load HYDAT data > par(mfrow=c(3,1)) > path <- 'c:\\HYDAT' > wsc.id <- '11AB075' > stn <- ReadHydatFile(path, wsc.id) #if data in CDROM image > # stn <- ReadHydatDatabase (path, wsc.id) #if data in database >
I'd need access to the whole data file. I tried exporting some data from the website for it but it got too complex for me! However, it seems to me you have two chunks of data: stn[flow] - which has daily flow data in it? stn[metadata] which i guess is a header for the whole dataset -describing what it is. So I recreated what i hope might be simillar to part of your data (using lst instead of stn as the vector/array/list name) # Build an array containing a lat & long. info <- data.frame(latitude=1.0005689, longitude=55.698754) #display result info # latitude longitude #1 1.000569 55.69875 #create a list (called lst) with an object metadata in it containing the array lst <- list (metadata=info) #display result lst #$metadata # latitude longitude #1 1.000569 55.69875 #check if can call a single piece of data using the square brackets as references... lst[['metadata']][['longitude']] #[1] 55.69875 #now try rounding that > round (lst[['metadata']][['longitude']], digits=2) [1] 55.7 #now try sprintf'ing that sprintf('Seasonal station with natural streamflow - Lat: %s', round (lst[['metadata']][['longitude']], digits=2)) # [1] "Seasonal station with natural streamflow - Lat: 55.7" #now try that in a plot plot(1,1, sub=sprintf('Seasonal station with natural streamflow - Lat: %s', round (lst[['metadata']][['longitude']], digits=2))) # results in a correct label ;-) Its possible to refer to that same value in the following ways: > lst$metadata # same as lst[['metadata']] latitude longitude 1 1.000569 55.69875 > lst$metadata[['longitude']] # same as lst[['metadata']][['longitude']] [1] 55.69875 > lst$metadata$longitude # same as lst[['metadata']][['longitude']] [1] 55.69875 > So I'm stumped! without being able to see the actual structure of your data I can't figure out why you are getting an error! BTW - was there a cut and paste error? Your error message was reported as: Error: unexpected symbol in: " sub = sprintf('Seasonal station with natural streamflow - Lat: %s Lon: %s Gross Area %s km\UB2 - Effective Area %s km\UB2, + round( [['metadata" > + round( [['metadata']][['longitude']], digits = 4), Error: unexpected '[[' in "+ round( [[" The + on + round looks like the plus was typed. + shouldn't have been typed, but also was there a missing quote after the \UB2. You should have entered: sub = sprintf('Seasonal station with natural streamflow - Lat: %s Lon: %s Gross Area %s km\UB2 - Effective Area %s km\UB2 ', round( [['metadata']][['latitude']], digits=4 ), round( [['metadata']][['longitude']], digits = 4), round( [['metadata']][['grossarea']], digits = 4), round( [['metadata']][['effectivearea']], digits = 4)) C ******************************************************************************************************************** This message may contain confidential information. If yo...{{dropped:21}} ______________________________________________ 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.