[R] Superscripts and rounding
ehux
emily.huxter at ec.gc.ca
Thu Jul 30 17:32:18 CEST 2009
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! (oh right you need the
HYDAT package - sorry about that) =)
However, it seems to me you have two chunks of data: you got it!!!
stn[flow] - which has daily flow data in it? Correct
stn[metadata] which i guess is a header for the whole dataset -describing
what it is. Correct
Below is a small section of the data. I tried copying and pasting your new
sub = code but i still get the same error. It is so weird it should work the
logic is there!!!
> str(Lyons)
List of 3
$ metadata:List of 7
..$ id : chr "11AB075"
..$ name : chr "LYONS CREEK AT INTERNATIONAL BOUNDARY"
..$ latitude : num 49
..$ longitude : num -109
..$ provstate : chr "SK"
..$ grossarea : num 174
..$ effectivearea: num 136
$ flow :List of 7
..$ daily :'data.frame': 28124 obs. of 3 variables:
.. ..$ date :Class 'Date' num [1:28124] -15706 -15705 -15704 -15703
-15702 ...
.. ..$ value: num [1:28124] NA NA NA NA NA NA NA NA NA NA ...
.. ..$ flag : Factor w/ 4 levels "","B","E","A": 1 1 1 1 1 1 1 1 1 1 ...
..$ monthly :'data.frame': 924 obs. of 4 variables:
.. ..$ year : int [1:924] 1927 1927 1927 1927 1927 1927 1927 1927 1927
1927 ...
.. ..$ month: int [1:924] 1 2 3 4 5 6 7 8 9 10 ...
.. ..$ value: num [1:924] NA NA 0.466 2.49 1.46 ...
.. ..$ flag : Factor w/ 1 level "": 1 1 1 1 1 1 1 1 1 1 ...
..$ annual :'data.frame': 19 obs. of 3 variables:
.. ..$ year : num [1:19] 1930 1931 1932 1933 1934 ...
.. ..$ value: num [1:19] 0.167 0 0.004 0 0.04 ...
.. ..$ flag : chr [1:19] "" "" "" "" ...
..$ annual.maxima :'data.frame': 77 obs. of 3 variables:
.. ..$ date :Class 'Date' num [1:77] -15564 -15249 -14821 -14519 -14245
...
.. ..$ value: num [1:77] 14.3 10.7 0.603 10.7 0 ...
.. ..$ flag : chr [1:77] "" "B" "" "B" ...
..$ annual.minima :'data.frame': 77 obs. of 3 variables:
.. ..$ date :Class 'Date' num [1:77] -15647 -15281 -14916 -14610 -14245
...
.. ..$ value: num [1:77] 0 0 0 0 0 0 0 0 0 0 ...
.. ..$ flag : chr [1:77] "" "B" "" "" ...
..$ instantaneous.maxima:'data.frame': 62 obs. of 4 variables:
.. ..$ date : chr [1:62] "1927-04-03 19:00:00" "1928-04-02 00:00:00"
"1929-06-11 00:00:00" "1930-04-02 07:00:00" ...
.. ..$ timezone: chr [1:62] "MS" " " " " "MS" ...
.. ..$ value : num [1:62] 18.9 15.8 0.796 12.4 0.708 ...
.. ..$ flag : chr [1:62] "" "B" "" "B" ...
..$ daily.flag.summary :List of 2
.. ..$ by.year :'data.frame': 77 obs. of 6 variables:
.. .. ..$ year : num [1:77] 1927 1928 1929 1930 1931 ...
.. .. ..$ A : int [1:77] 0 0 0 0 0 0 0 0 0 0 ...
.. .. ..$ B : int [1:77] 12 40 0 61 0 0 0 51 0 0 ...
.. .. ..$ E : int [1:77] 0 2 1 3 0 0 0 0 0 0 ...
.. .. ..$ MISSING: int [1:77] 120 118 59 0 0 0 0 0 0 0 ...
.. .. ..$ NOFLAG : int [1:77] 233 206 305 301 365 366 365 314 365 366 ...
.. ..$ by.month.year:'data.frame': 924 obs. of 7 variables:
.. .. ..$ year : num [1:924] 1927 1927 1927 1927 1927 ...
.. .. ..$ month : num [1:924] 1 2 3 4 5 6 7 8 9 10 ...
.. .. ..$ A : int [1:924] 0 0 0 0 0 0 0 0 0 0 ...
.. .. ..$ B : int [1:924] 0 0 0 12 0 0 0 0 0 0 ...
.. .. ..$ E : int [1:924] 0 0 0 0 0 0 0 0 0 0 ...
.. .. ..$ MISSING: int [1:924] 31 28 0 0 0 0 0 0 0 0 ...
.. .. ..$ NOFLAG : int [1:924] 0 0 31 18 31 30 31 31 30 31 ...
$ level : NULL
>
$flow$daily
date value flag
22536 1988-09-12 0.000
22537 1988-09-13 0.000
22538 1988-09-14 0.000
22539 1988-09-15 0.000
22540 1988-09-16 0.000
22541 1988-09-17 0.000
22542 1988-09-18 0.000
22543 1988-09-19 0.000
22544 1988-09-20 0.000
22545 1988-09-21 0.000
22546 1988-09-22 0.000
22547 1988-09-23 0.000
22548 1988-09-24 0.000
$flow$monthly
year month value flag
1 1927 1 NA
2 1927 2 NA
3 1927 3 0.466
4 1927 4 2.490
5 1927 5 1.460
6 1927 6 0.042
7 1927 7 0.318
8 1927 8 0.020
9 1927 9 0.000
10 1927 10 0.000
11 1927 11 NA
12 1927 12 NA
13 1928 1 NA
14 1928 2 NA
15 1928 3 0.184
16 1928 4 1.200
17 1928 5 0.008
18 1928 6 0.000
19 1928 7 0.000
$flow$annual
year value flag
1 1930 0.167
2 1931 0.000
3 1932 0.004
4 1933 0.000
5 1934 0.040
6 1935 0.072
7 1936 0.061
9 1937 NA
10 1938 NA
11 1939 NA
12 1940 NA
$flow$annual.maxima
date value flag
1 1927-05-23 14.300
2 1928-04-02 10.700 B
3 1929-06-04 0.603
4 1930-04-02 10.700 B
5 1931-01-01 0.000
6 1932-06-11 0.362
7 1933-01-01 0.000
8 1934-03-03 2.520 B
9 1935-04-13 7.020
10 1936-04-12 11.000
11 1937-04-09 2.800
12 1938-04-09 3.140 B
13 1939-03-22 10.500
14 1940-04-21 15.100
15 1941-03-22 8.070
$flow$annual.minima
date value flag
1 1927-03-01 0
2 1928-03-01 0 B
3 1929-03-01 0
4 1930-01-01 0
5 1931-01-01 0
6 1932-01-01 0
7 1933-01-01 0
8 1934-01-01 0
9 1935-01-01 0
10 1936-01-01 0
11 1937-01-01 0
12 1938-03-01 0
$flow$instantaneous.maxima
date timezone value flag
1 1927-04-03 19:00:00 MS 18.900
2 1928-04-02 00:00:00 15.800 B
3 1929-06-11 00:00:00 0.796
4 1930-04-02 07:00:00 MS 12.400 B
5 1932-06-10 19:00:00 MS 0.708
6 1934-03-03 07:00:00 MS 3.260 B
7 1935-04-13 07:00:00 MS 12.800
8 1936-04-12 18:00:00 MS 14.300
9 1937-04-09 05:00:00 MS 5.210
10 1938-03-25 18:30:00 MS 4.110
11 1939-03-23 01:00:00 MS 17.100
$flow$daily.flag.summary
$flow$daily.flag.summary$by.year
year A B E MISSING NOFLAG
1 1927 0 12 0 120 233
2 1928 0 40 2 118 206
3 1929 0 0 1 59 305
4 1930 0 61 3 0 301
5 1931 0 0 0 0 365
6 1932 0 0 0 0 366
7 1933 0 0 0 0 365
8 1934 0 51 0 0 314
9 1935 0 0 0 0 365
10 1936 0 0 0 0 366
11 1937 0 0 0 61 304
12 1938 0 13 1 120 231
13 1939 0 0 0 120 245
14 1940 0 2 2 121 241
15 1941 0 0 0 120 245
16 1942 0 5 0 120 240
17 1943 0 0 0 120 245
$flow$daily.flag.summary$by.month.year
year month A B E MISSING NOFLAG
1 1927 1 0 0 0 31 0
2 1927 2 0 0 0 28 0
3 1927 3 0 0 0 0 31
4 1927 4 0 12 0 0 18
5 1927 5 0 0 0 0 31
6 1927 6 0 0 0 0 30
7 1927 7 0 0 0 0 31
8 1927 8 0 0 0 0 31
9 1927 9 0 0 0 0 30
10 1927 10 0 0 0 0 31
11 1927 11 0 0 0 30 0
12 1927 12 0 0 0 31 0
13 1928 1 0 0 0 31 0
14 1928 2 0 0 0 29 0
decade <- subset(stn[['flow']][['daily']], date >= dates[1] & date <=
dates[2])
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:14}}
More information about the R-help
mailing list