Reputation:
Suppose i have some dataframes A_January, A_February, A_December etc with some 10 columns each...
All of them have the same 10 columns.. I need to do some data manipulation on one of the 10 columns and produce a new bunch of columns in each of the data frames.. I can do this manually for all dataframes, but i have 400 such dataframes..
How do i do this?. please let me know... Suppose, i need to do the same set of operations on multiple dataframes...(create new variables, sort them etc etc) A_January$New_var<-A_January$Var1+A_January$Var2
How do i do this?. How can i put this in a loop and make it happen? PLease let me know
Upvotes: 2
Views: 1537
Reputation: 89057
First step is very important: do not create a variable for each data.frame. Instead, put them all into a list of data.frames:
data <- list(A_January, A_February, A_December)
This might look cumbersome to type, especially if you have hundreds of data.frames. So if you can tell us how you came to create these data.frames we might help fix the problem at the root.
Once you have a list, it is very easy to modify all of them:
data <- lapply(data, transform, New_var = Var1 + Var2)
Upvotes: 1