[R] if - else
jim holtman
jholtman at gmail.com
Wed Jul 25 20:58:10 CEST 2007
try:
Start <- ifelse (DateFirstEven < DateSecondEvent,
(DateFirstEvent+DateSecondEvent)/2, DateFound)
On 7/25/07, James J. Roper <jjroper at gmail.com> wrote:
> Greetings,
>
> I have some confusion with the use of if - else. Let's say I have a
> four variables as follows:
>
> Condition DateFound DateFirstEvent
> DateSecondEvent
> NA 10Jan2000 NA NA
> 0 05Jan2000 07Jan2000
> 10Jan2000
> 1 07Jan2000 07Jan2000
> 08Jan2000
> 2 09Jan2000 NA NA
>
> Now, what I need to do is make a new variable that is either the
> midpoint of the first and second event dates, or the date found (I
> will call Start).
>
> I tried an if - else condition as follows:
>
> Start <- if (DateFirstEven < DateSecondEvent)
> (DateFirstEvent+DateSecondEvent)/2 else DateFound
>
> I also tried
>
> Start <- if (any(DateFirstEven < DateSecondEvent))
> (DateFirstEvent+DateSecondEvent)/2 else DateFound
>
> Only the first half of the expression was ever evaluated.
>
> I hope I have not been to brief, and will certainly appreciate any help.
>
> Thanks,
>
> Jim
>
> --
> James J. Roper
> Population Dynamics and Conservation of
> Terrestrial Vertebrates
> Caixa Postal 19034
> 81531-990 Curitiba, Paraná, Brasil
> =======================================
> E-mail: jjroper at gmail.com
> Phone/Fone/Teléfono: 55 41 33611764
> celular: 55 41 99870543
> Casa: 55 41 33857249
> =======================================
> Ecologia e Conservação na UFPR
> http://www.bio.ufpr.br/ecologia/
> ---
> http://jjroper.googlepages.com/
> http://arsartium.googlepages.com/
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
More information about the R-help
mailing list