[R] Superscripts and rounding
Polwart Calum (County Durham and Darlington NHS Foundation Trust)
calum.polwart at nhs.net
Tue Jul 28 23:26:22 CEST 2009
Slightly confused because if I try:
> newdata.yaxis = c(2.0000473, 3.123456, 3.23456, 2.67890, 1.56789)
> newdata.yaxis_4 = round (newdata.yaxis, digits = 4)
> newdata.yaxis
[1] 2.000047 3.123456 3.234560 2.678900 1.567890
> newdata.yaxis_4
[1] 2.0000 3.1235 3.2346 2.6789 1.5679
As you see - I get a new variable with the result rounded to 4 places.
Then if I try:
> inserted = sprintf("Some text with a 4 digit number ( %s ) inserted in it", newdata.yaxis_4[2])
> inserted
[1] "Some text with a 4 digit number ( 3.1235 ) inserted in it"
It works for me - clearly the way my data is structured is a little different from you. Would have thought you might need to do something like:
> [['rounddata']] = round ([['metadata']], digits = 4)
Then call your data with [['rounddata']][['latitude']] etc - I'm no expert on all this matrixes stuff though! (Not even sure what a double [[ means! )
But this (calling the round within the sprintf function) also works for me:
> inserted = sprintf("Some text with a 4 digit number ( %s ) inserted in it",round( newdata.yaxis[2], digits = 4))
> inserted
[1] "Some text with a 4 digit number ( 3.1235 ) inserted in it"
So why can't you just use:
> 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),
+ )
********************************************************************************************************************
This message may contain confidential information. If yo...{{dropped:21}}
More information about the R-help
mailing list