[R] grid: dividing units by numbers
Paul Murrell
p.murrell at auckland.ac.nz
Wed Oct 29 21:00:42 CET 2003
Hi
Deepayan Sarkar wrote:
> On Wednesday 29 October 2003 09:36, Wolfram Fischer wrote:
>
>>How can I divide a unit by an number
>>or average a vector of units, e.g.:
>>
>> u1 <- unit( 3, 'npc' )
>> u2 <- unit( 6, 'npc' )
>>
>> u1 / 2
>
>
> 0.5 * u1
>
>
>> ( u1 + u2 ) / 2
>
>
> 0.5 * (u1 + u2)
>
>
>> mean( unit.c(u1,u2) )
>
>
> Not sure if that's generally doable (other than adding all the units one at a
> time in a loop and then multiplying by 1/length).
u <- unit.c(u1, u2)
1/unit.length(u) * sum(u)
> But if all your units are going to be "npc", you might as well keep the 'x'-s
> separate and do arithmetic on them.
There are a limited set of mathematical functions/operators for grid
units so far.
These include: +, -, and *; sum(), min(), and max().
There are also some unit-specific versions of some other useful
functions: unit.c(), unit.rep(), unit.length(), unit.pmin(), unit.pmax()
For more complex calculations involving units, you may need to look at
grid.convert() (but take note of the warning on its help page).
Paul
--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/
More information about the R-help
mailing list