Skip to content
Prev 294711 / 398502 Next

simple question about max(x,y)

On May 15, 2012, at 8:42 PM, lapertem4 wrote:

            
Option one:
 > test <- function(x,y) { c("x","y")[which.max(c(x,y))]}
 > test(3,4)
[1] "y"
 > test(4,3)
[1] "x"

Option two:
 > test <- function(x,y) { xn <- deparse(substitute(x)); yn <-  
deparse(substitute(y)); c(xn, yn)[which.max(c(x,y))]}
 > test(4,3)
[1] "4"
 > test(x,y)
[1] NA
 > x=4
 > y=3
 > test(x,y)
[1] "x"