s-news
[Top] [All Lists]

factorial

To: s-news@lists.biostat.wustl.edu
Subject: factorial
From: J Liang <jl78150@yahoo.com>
Date: Fri, 21 Mar 2003 09:54:08 -0800 (PST)
Here is my original query: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.


things that helped me clarify the confusion are the
basic of S explained by the great users in this
community.   

Tim Hesterberg, Patric Burns,  Nick Eliis, Spencer
Graves,and  David Harris all offered their hand in
essentially explaned that S's basic data structure is
vector, and logical vectors are not coerced to
numberic in subscripting.(which was my confusion). 
And Patric Burns offered a website with Spoetry and 
"a guide for the unwilling S user".  The address is:
http://www.burns-stat.com/   I have gone through the
"a guide for the unwilling S user" and is going
through the Spoetry.  Very grateful for the resource.
Nick Eliis also suggested to use the help function on
help("["). 

Thanks again for all the help.  I hope this summary
helps for other new users. And thanks for David and
Madeline for point out to me the right etiqutte of
summarizing query.    

Josephine

__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com

<Prev in Thread] Current Thread [Next in Thread>