[R] functions different in R and S
Spencer Graves
spencer.graves at pdf.com
Wed Feb 19 18:59:06 CET 2003
Also, many of the probability distribution functions are better in R
1.6.2 than in S-Plus 6.1. For example, in R, most of the functions will
work with the logarithm of the probability (or density) using argument
"log.x"; S does not have this argument.Simularly, probability functions
that could have a noncentrality parameter are more likely to have it in
R than in S-Plus.
I had trouble over a year ago with numerical precision with some
probability functions in S-Plus 2000, but I can't recall the details
now. If you are estimating degrees of freedom in Student's t
distribution, e.g., to model kurtosis, you don't want the functions to
malfunction for unusual values of the argument df. I just sent S-Plus
6.1 into an incredibly long computation with pt(-1.96, df=1e99); R
returned a sensible answer immediately. If you are trying to estimate
df numerically, it is better not to have this.
Spencer Graves
David Brahm wrote:
> Helen Yang <Huiqin.Yang at noaa.gov> wrote:
>
>>I wonder whether there is any resource that can point to useful
substitutes
>>for S functions that are not recognized by R. At the same time
whether there
>>is a list of functions, which appear in both R and S but which don't do
>>exactly the same thing.
>
>
> As Prof. Brian D. Ripley <ripley at stats.ox.ac.uk> said, see the FAQ at:
> <http://www.r-project.org/> (Click "FAQs", "R FAQ", "R and S".)
>
> Here are my own crib notes on some differences that I care about.
Note "S"
> here really means S-Plus version 6.1.2. I have not checked whether
any of
> these have changed since October. This list is certainly not complete.
>
> *** R vs. S (DB 10/28/02) ***
>
> Language differences:
> - Scoping rules differ. In R, functions see the functions they're
in. Try:
> f1 <- function() {x <- 1; f2 <- function() print(x); f2()}; f1()
> - Data must be loaded explicitly in R, can be attach()'ed in S.
> Addressed by my contributed package "g.data".
> - R has a character-type NA, so LETTERS[c(NA,2)] = c(NA,"B") not
c("","B")
> - paste("a","b", sep="|", sep=".") is an error in R; ok in S.
> - for() loops more efficient in R.
>
> Graphics differences:
> - Log scale indicated in S with par(xaxt)=="l", in R with par("xlog")==T.
> - R has cex.main, col.lab, font.axis, etc. Thus title("Hi", cex=4)
fails.
> - R has plotmath and Hershey vector fonts.
> - R has palette(rainbow(10)) to define colors (both screen and printer).
>
> Functions missing from R:
> - unpaste, slice.index, colVars
>
> Functions missing from S:
> - strsplit, sub, gsub, chartr, formatC
>
> Functions that work differently:
> - system() has no "input" argument in R.
> - substring(s,"x") <- "X" only works in S, but R has s <-
gsub("x","X",s).
> - scan expects numbers by default in R.
> - which(<numeric>) converts to logical in S, is an error in R.
> - The NULL returned by if(F){...} is invisible in R, visible in S.
> - The NULL returned by return() is visible in R, invisible in S.
> - Args to "var" differ, and R has "cov". S na.method="a" ~ R use="p".
> - var (or cov) drops dimensions in S, not R.
> - cut allows labels=F in R, not in S (also left.include=T becomes
right=F).
> - Last argument of a replacement function must be named "value" in R.
> - tapply(1:3, c("a","b","a"), sum) is a 1D-array in R, a vector in S.
>
More information about the R-help
mailing list