I am trying to dynamically name the output of a data frame based upon the inputs.
get.max2 <- function(data = NULL, column)
{
#require(qdap)
col <- eval(substitute(column), data)
max <- max(eval(substitute(column), data))
name <- lookup(col, max, rownames(data))
name <- name[!is.na(name)]
#title <- do.call('paste', list(paste(match.call()[1])))
df <- data.frame(name = name, title = max(col))
print(df)
}
Currently, the output looks like this:
get.max2(mtcars, mpg)
name title
Volvo 142E 33.9
But, I want it to look like this:
get.max2(mtcars, mpg)
name mpg
Volvo 142E 33.9
I think the answer has something to do with match.call/do.call, but my knowledge is fuzzy at best when using these functions. Anyone know if this possible?
Thanks for your help!