I'd like to pass a data frame into lapply via %>%
, but I need to be able to access the names of the columns, so my lapply arguments are something like this:
mydf %>%
lapply( 1:length(.), function(x) {
manipulate_df( mydf[x], using_column_names(names(mydf)[x] )
})
However, when I try that, I get the following error:
Error in match.fun(FUN) :
'1:length(.)' is not a function, character or symbol
As far as I can tell R and lapply don't like 1:length(.)
. I suppose a valid option is breaking the chain, but I'd like to learn how to do it properly.