An interesting thing that I found while doing the analysis for my previous post on the Canterbury earthquakes, was the difficulty of constraining figures less than a negative number. For example:

a<-seq(1, 10, 1)

b<-a[a>3 & a<7]

c<-seq(-1, -10, -1)

d<-c
> a

[1] 1 2 3 4 5 6 7 8 9 10

> b

[1] 4 5 6

> c

[1] TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE

> d

[1] -1 -2 -3 -4 -5 -6

The boolean operator for selecting a range less than a negative number ends up being the same as the assignment operator. To get around this I simply define the function neg()

neg<-function(x) -x

c<-seq(-1, -10, -1)

d<-c
> c

[1] -1 -2 -3 -4 -5 -6 -7 -8 -9 -10

> d

[1] -4 -5 -6

*Related*

If you got this far, why not

__subscribe for updates__ from the site? Choose your flavor:

e-mail,

twitter,

RSS, or

facebook...