I have data frames A, B, C, ... and you want to change each data frame in the same way, for example. redefinition factors of factors that are present in all data frames:
A = data.frame( x=c('x','x','y','y','z','z') ) B = data.frame( x=c('x','y','z') ) C = data.frame( x=c('x','x','x','y','y','y','z','z','z') ) A$x = factor( A$x, levels=c('z','y','x') ) B$x = factor( B$x, levels=c('z','y','x') ) C$x = factor( C$x, levels=c('z','y','x') )
This becomes time consuming if there are many data frames and / or many changes. How can I do this briefly using a loop or something better? Direct approach e.g.
for ( D in list( A, B, C ) ) { D$x = factor( D$x, levels=c('z','y','x') ) }
does not work because it does not change the original data frames.
EDIT: Added definitions of A, B, and C to make it reproducible.