[R] how to do Splus compare() function in R [Broadcast]
Liaw, Andy
andy_liaw at merck.com
Fri Apr 21 05:36:53 CEST 2006
You need to tell us what compare() in S-PLUS does; i.e., what does it take
as input and what does it output. Presumably the information would be in
the help page for compare().
Telling us what the function looks like in S-PLUS is of no use, since most
likely the code cannot be used in R without violating S-PLUS copyright
and/or license. Even if that wasn't an obstacle, the fact that it calls
.Internal() says the actual code is written in C, and of course no one
outside of Insightful (and perhaps Bell Labs) has access to code at that
level. And even then, R and S-PLUS are not likely to be compatible at that
level.
Andy
From: Bellinger Instruments P/L
>
> The sign() function requires one argument,
> and returns the sign of the value, where I require a number
> -1, 0, or 1 depending on if the value is <, ==, or > the
> first argument.
>
> This is the Splus function when listed,
> > compare
> function(e1, e2)
> .Internal(compare(e1, e2), "do_op", T, 18)
>
> unfortunately I do not understand the .internal function
> and cannot find any description of this type of programming
> on the CRAN site
>
>
>
> This is how I am using it in the source file.
>
>
> zz <- readline() # keyboard input eg: f15
>
>
> if (charmatch(substring(zz,1,1),"f",
> nomatch=-1) >0){
> ii <- as.numeric(substring(zz,2,99))
>
> iii <- compare(ii*1e9,f) # f is a vector of
> length(146) frequencies
> # compare() searches thru f and
> # creates vector iii with
> # -1 if numeric is < f[i],
> # 0 if numeric is == f[i], and
> # 1 if numeric is > f[i]
>
> # the end result is a vector(iii) length(146)
> # with -1,0,1 if the numeric is in f
>
>
> i <- match(-1,c(iii,-1))-1 # if vector(iii) contains 0
> assign the index
> }
>
> # error traps for if 0 is not in vector(iii)
>
> if (i<1){cat("Min n = 1\n")
> i <- 1}
> if (i>length(f)){cat("Max n =",length(f),"\n")
> i <- length(f)}
>
> -----Original Message-----
> From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk]
> Sent: Thursday, 20 April 2006 4:02 PM
> Subject: Re: [R] how to do Splus compare() function in R
>
> You would need to tell us what it does (and what the inputs are).
>
> I think it is likely that compare(x, y) in S-PLUS is the same
> as sign(x-y) in R, at least with numeric vector inputs.
>
> --
> Bob Kelly lab at bellinger.com.au
> Metrologist & Microwave Eng. http://www.bellinger.com.au
> Bellinger Instruments Pty Ltd Tel: 612 9684 1442
> 4 Muriel Ave Fax: 612 9638 4435
> Rydalmere NSW
> Australia 2116
>
> ______________________________________________
> R-help at 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
>
>
More information about the R-help
mailing list