[R] function to compare numbers
    jim holtman 
    jholtman at gmail.com
       
    Fri Sep  3 16:06:57 CEST 2010
    
    
  
> x <- 2
> y <- 3
> ifelse(x > y, 1, ifelse(x < y, -1, 0))
[1] -1
On Fri, Sep 3, 2010 at 9:33 AM, Hyunchul Kim <hyunchul.kim.sfc at gmail.com> wrote:
> Hi, all
>
> is there a built-in function to compare two numbers?
>
> something like following function
>
> cmp <- function(x, y){
>    value <- 0
>    if (x > y){
>        value <- 1
>    }else if (x == y){
>        value <- 0
>    }else {
>        value <- -1
>    }
>    return(value)
> }
>
> Thanks in advance,
>
> Hyunchul
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
    
    
More information about the R-help
mailing list