What I'd like to do is apply a function to multiple columns in a dataframe, recording the output as a new column. To make this clearer, I'd like to take a dataframe of the form:
first_name last_name age
Alice Smith 45
Bob Richards 20
to:
first_name last_name age first_name_lower last_name_lower
Alice Smith 45 alice smith
Bob Richards 20 bob richards
I can do this column-wise with something like:
df$first_name_lower <- apply(df[,c('first_name')], 1, function(x) str_to_lower(x))
df$last_name_lower <- apply(df[,c('last_name')], 1, function(x) str_to_lower(x))
but of course for multiple columns this isn't a particularly elegant solution.
Thanks!