On Sat, 7 Oct 2006, Rolf Turner wrote: > Peter Dalgaard writes: > >> Alberto Vieira Ferreira Monteiro <[EMAIL PROTECTED]> writes: >> >>> Why this kind of assignment does not work? >>> >>> n <- 1 >>> f <- ifelse(n == 1, sin, cos) >>> f(pi) >> >> It's not supposed to. >> >> 'ifelse' returns a value with the same shape as 'test' which is >> filled with elements selected from either 'yes' or 'no' depending >> on whether the element of 'test' is 'TRUE' or 'FALSE'. >> >> which makes very little sense if yes and no are functions. > > I think that's a debatable assertion. Why might I > not want a vector, or rather a list, of functions? >
You might want a list of functions, but in that case ifelse() would have to return a list of functions, and in the example in question it would return list(sin) rather than sin. There is a real difference between lists of functions and the things that rep() works on, in that a vector of one number is the same as that number, but a list of one function is not the same as the function. -thomas Thomas Lumley Assoc. Professor, Biostatistics [EMAIL PROTECTED] University of Washington, Seattle ______________________________________________ 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.