Hi, all
I am a newbie at s-plus, I am using splus 6.1, windows
xp. There is some thing I could not explain about a
system function factorial, maybe there is something
fundatmental about s-plus I am not clear. I would
appreciate any help.
When reading the following code of the system function
factorial, my understanding is that after caculate the
result, the function then goes on checking to see if n
is an integer, if it is, it would round the result and
assign it back to result. Therefore, if it is not an
integer, the wasInteger parameter would be F, which is
coersed to be 0 in the next step. With the indexing
of vector started at 1,
result[0] should not have anything returned. However,
if I give 5.5 or another n with a decimal , I would
have a decimal returned value. factorial(5.5) gives
the following output:287.8853
here is the system function:
factorial <-function(n)
{
result <- gamma(n + 1)
wasInteger <- !(n %% 1) & !is.na(n)
result[wasInteger] <- round(result[wasInteger])
result
}
Thanks for any help.
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
|