I have data frames A, B, C, ... and want to modify each data frame in the same way, e.g. re-ordering factors levels of a factor which is present in all of the 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 gets laborious if there are lots of data frames and/or lots of modifications to be done. How can I do it concisely, using a loop or something better? A straightforward approach like
for ( D in list( A, B, C ) ) {
D$x = factor( D$x, levels=c('z','y','x') )
}
does not work, because it doesn't modify the original data frames.
EDIT: added definitions of A, B, and C to make it reproducible.