[R] Transform counts into presence/absence

Rui Barradas ruipbarradas at sapo.pt
Thu May 31 13:18:31 CEST 2012


Hello,

Try

x <- c(1,0,21,2,0,0,234,2,0)
as.integer(x != 0)

Hope this helps,

Rui Barradas


Em 31-05-2012 12:13, Johannes Radinger escreveu:
> Hi,
>
> I am looking for a very easy way to transform
> a column in a dataframe from counts (eg. c(1,0,21,2,0,0,234,2,0))
> into a binary form to get presence/absence values
> e.g. c(1,0,1,1,0,0,1,1,0). Is there a simple built-in function?
> or do I have do to it with a replaceement funciton using IF x>  0
> THEN 1 etc.?
>
> /johannes



More information about the R-help mailing list