On Sep 3, 2010, at 9:33 AM, Hyunchul Kim 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)
}


Not that I know of, but there is an obvious application of sign():

cmp <-function(x,y) sign(y-x)


--

David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@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.

Reply via email to