I've written an apply where I want to 'loop' over a subset of the columns in a dataframe and print some output. For the sake of an example I'm just transforming based on dividing one column by another (I know there are other ways to do this) so we have:
apply(df[c("a","b","c")],2,function(x){
z <- a/df[c("divisor")]
}
)
I'd like to print the column name currently being operated on, but colnames(x) (for example) doesn't work.
Then I want to save a new column, based on each colname (a.exp,b.exp or whatever) into the same df.