[R] if - else

James J. Roper jjroper at gmail.com
Wed Jul 25 19:20:46 CEST 2007


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/



More information about the R-help mailing list