[R] Transform counts into presence/absence

Duncan Mackay mackay at northnet.com.au
Fri Jun 1 00:58:00 CEST 2012


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:


>-------- Original-Nachricht --------
> > Datum: Thu, 31 May 2012 11:16:32 +0000
> > Von: "ONKELINX, Thierry" <Thierry.ONKELINX at inbo.be>
> > An: Johannes Radinger <JRadinger at gmx.at>, "R-help at r-project.org" 
> <R-help at r-project.org>
> > Betreff: RE: [R] Transform counts into presence/absence
>
> > Just use the logical operators.
>
>
>of course, that simple :) . thank you!
>
>
> >
> > Counts <- c(1,0,21,2,0,0,234,2,0)
> > Counts > 0
> > 1 *(Counts > 0)
> >
> > ir. Thierry Onkelinx
> > Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
> > Forest
> > team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
> > Kliniekstraat 25
> > 1070 Anderlecht
> > Belgium
> > + 32 2 525 02 51
> > + 32 54 43 61 85
> > Thierry.Onkelinx at inbo.be
> > www.inbo.be
> >
> > To call in the statistician after the experiment is done may be no more
> > than asking him to perform a post-mortem examination: he may be able to say
> > what the experiment died of.
> > ~ Sir Ronald Aylmer Fisher
> >
> > The plural of anecdote is not data.
> > ~ Roger Brinner
> >
> > The combination of some data and an aching desire for an answer does not
> > ensure that a reasonable answer can be extracted from a given body of data.
> > ~ John Tukey
> >
> >
> > -----Oorspronkelijk bericht-----
> > Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> > Namens Johannes Radinger
> > Verzonden: donderdag 31 mei 2012 13:13
> > Aan: R-help at r-project.org
> > Onderwerp: [R] Transform counts into presence/absence
> >
> > 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
> > --
> >
> > Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
> >
> > ______________________________________________
> > R-help at 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.
> > * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
> > Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver
> > weer en binden het INBO onder geen enkel beding, zolang dit bericht niet
> > bevestigd is door een geldig ondertekend document.
> > The views expressed in this message and any annex are purely those of the
> > writer and may not be regarded as stating an official position of INBO, as
> > long as the message is not confirmed by a duly signed document.
>
>--
>
>Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
>
>______________________________________________
>R-help at 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.



More information about the R-help mailing list