Suppose you are trying to create a data frame inside a function. I would like to be able to predefine the column names as one of the function parameters. Take the following code:
foo <- function(a) { answer <- data.frame(a=1:5) return(answer) }
In the above example, I would like to specify the value of the column name in the foo() function, for example. foo('my.name') so that the response has the column name my.name instead of a . I suppose you could code this in a function using colnames() , but I was interested in an alternative approach.
source share