Bellinger Instruments P/L
2006-Apr-20 02:04 UTC
[R] how to do Splus compare() function in R
Hi I have a source file in Splus that fails in R as I am using the Splus function compare(). compare( ii * 1e9,f ) where ii is a single variable and f is a vector of length 146 R returns with no function error Can anyone inform me how I can do this in R thanks in advance Bob Kelly [[alternative HTML version deleted]]
Bellinger Instruments P/L
2006-Apr-20 02:06 UTC
[R] how to do Splus compare() function in R
Hi I have a source file in Splus that fails in R as I am using the Splus function compare(). compare( ii * 1e9,f ) where ii is a single variable and f is a vector of length 146 R returns with no function error Can anyone inform me how I can do this in R thanks in advance Bob Kelly Bellinger Instruments Pty Ltd [[alternative HTML version deleted]]
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. On Thu, 20 Apr 2006, Bellinger Instruments P/L wrote:> Hi > I have a source file in Splus that fails in R as I am using the Splus > function compare(). > > compare( ii * 1e9,f ) where ii is a single variable and f > is a vector of length 146 > > R returns with no function error > > Can anyone inform me how I can do this in R > > > thanks in advance > > Bob Kelly > > Bellinger Instruments Pty Ltd > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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 >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Bellinger Instruments P/L
2006-Apr-21 03:01 UTC
[R] how to do Splus compare() function in R
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,> comparefunction(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