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

______________________________________________
R-help@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.

Reply via email to