Suppose you're trying to create a data frame within a function. I would like to be able to define the column names ahead of time as one of the parameters of the function. Take the following code:
foo <- function(a) {
answer <- data.frame(a=1:5)
return(answer)
}
In the above example, I would like to be able to specify the value of the column name in the function foo()
, e.g. foo('my.name')
so that answer has the column name my.name
instead of a
. I imagine you could code this up within the function using colnames()
, but I was interested in an alternative approach.