Skip to content

Transform counts into presence/absence

2 messages · Duncan Mackay, Rui Barradas

#
Hi

I was curious on the possibilities -- what if an NA creeps in?

Counts <- c(1,0,21,2,0,0,234,2,0,NA)
Counts > 0
1 *(Counts > 0)
  [1]  1  0  1  1  0  0  1  1  0 NA

as.integer(x != 0)
[1] 1 0 1 1 0 0 1 1 0

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au
At 21:27 31/05/2012, you wrote:

            
#
Hello,

Actually, your output is wrong, you have compared the elements of a 'x', 
not Counts, to 0.

 > Counts <- c(1,0,21,2,0,0,234,2,0,NA)
 > Counts > 0
  [1]  TRUE FALSE  TRUE  TRUE FALSE FALSE  TRUE  TRUE FALSE    NA
 > 1 *(Counts > 0)
  [1]  1  0  1  1  0  0  1  1  0 NA
 > as.integer(Counts != 0)
  [1]  1  0  1  1  0  0  1  1  0 NA

Anyway, I hadn't thought of that. It's good to know how they behave.

Rui Barradas

Em 31-05-2012 23:58, Duncan Mackay escreveu: