On Nov 23, 2010, at 11:04 AM, Charles C. Berry wrote:
On Tue, 23 Nov 2010, Dennis Murphy wrote:
Interesting. Check this out:
u <- sample(c(TRUE, FALSE), 10, replace = TRUE)
[1] FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
[1] 0 0 1 0 0 1 0 0 0 0
v <- rpois(10, 3)
[1] TRUE FALSE TRUE TRUE TRUE TRUE FALSE TRUE FALSE TRUE
[1] TRUE FALSE TRUE TRUE TRUE TRUE FALSE TRUE FALSE TRUE
[1] 1 0 1 1 1 1 0 1 0 1
# Now assign !duplicated(v) to an object:
w <- !duplicated(v)
class(w)
[1] 1 0 1 1 1 1 0 1 0 1
I can see *what* is going on, but what is the reason for it? I see
another
notebook entry coming :)
See
?Arithmetic
and read the paragraph under Details starting 'Logical vectors'
Chuck;
Compare these three, all of which are using binary operators on logical
vectors which is what is being discussed in ?Arithmetic:
duplicated(c("a", "a", "b") ) + 0
!duplicated(c("a", "a", "b") ) + 0
0 + !duplicated(c("a", "a", "b") )
[1] 1 0 1
I believe the proper place to go is ?Syntax where operator precedence is
discussed. I think the precendence rules implicitly do this in the second
instance, because "+" has higher precendence than negation:
! ( duplicated(c("a", "a", "b") ) + 0 )