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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to