[R] ifelse(logical, function1, function2) does not work

Alberto Vieira Ferreira Monteiro albmont at centroin.com.br
Sat Oct 7 14:38:41 CEST 2006


Why this kind of assignment does not work?

  n <- 1
  f <- ifelse(n == 1, sin, cos)
  f(pi)

this must be rewritten as:

  n <- 1
  f <- cos
  if (n == 1) f <- sin
  f(pi)

[oops. 1.224606e-16 instead of zero. Damn floating point errors :-/]

Alberto Monteiro



More information about the R-help mailing list