x <- 3 y <- 4 max(x,y) 4 -------------------- how can i get the greater variable name y thanks -- View this message in context: http://r.789695.n4.nabble.com/simple-question-about-max-x-y-tp4630201.html Sent from the R help mailing list archive at Nabble.com.
On May 15, 2012, at 8:42 PM, lapertem4 wrote:> x <- 3 > y <- 4 > max(x,y) > 4 > -------------------- > how can i get the greater variable name > y >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" -- David Winsemius, MD West Hartford, CT