[R] Transform counts into presence/absence

Jim Lemon jim at bitwrit.com.au
Thu May 31 13:17:33 CEST 2012


On 05/31/2012 09:13 PM, Johannes Radinger wrote:
> 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.?
>
Hi Johannes,
Probably the easiest is:

testvec<-c(1,0,21,2,0,0,234,2,0)
newvec<-ifelse(testvec>0,1,0)

Jim



More information about the R-help mailing list