From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>

Date: Fri 13 May 2005 - 09:24:54 EST

Date: Fri 13 May 2005 - 09:24:54 EST

"Kevin E. Thorpe" <kevin.thorpe@utoronto.ca> writes:

*> rparab <- function(nn) {
**> u <- 2*runif(nn) - 1
**> ifelse(u<0,-(abs(u)^(1/3)),u^(1/3))
**> }
**>
*

> It seems that in my version of R (2.0.1) on Linux, that calculating the cube

*> root of a negative number using ^(1/3) returns NaN. I looked at the help in
**> the arithmetic operators and did help.search("cube root"),
**> help.search("root")
**> and help.search("cube") and recognised no alternatives. So I used an
**> ifelse() to
**> deal with the negatives. Have I missed something really elementary?
*

Not really. You might have used u <- runif(nn,-1,1) and sign(u)*abs(u)^(1/3) instead of the ifelse construct (remember that ifelse generally evaluates both the 'yes' and 'no' parts and on some architectures the NaN results may be slow to compute).

-- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 ______________________________________________ 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.htmlReceived on Fri May 13 09:29:31 2005

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:31:45 EST
*