I'd like to create multiple data frames with a for loop, and add a column and remove others from each of the new data frames. The original dataset looks something like this:
Site Count1 Count2 Count3 Count4 Count5 Count6 Count7 Count8 Count9 Habitat
1 0 0 0 0 1 0 2 0 1 Forest
2 1 2 3 0 0 2 0 1 0 Field
3 2 0 0 1 1 1 0 2 0 Field
Essentially I want to create a new data frame for each count column, so here I would have nine new dataframes that look like this:
df.1:
Site TotCount Habitat
1 0 Forest
2 1 Field
3 2 Field
df.2:
Site TotCount Habitat
1 0 Forest
2 2 Field
3 0 Field
And so on.
This creates the frames I need:
for (z in 1:9){
assign(paste("df",z,sep="."),orig_data)
}
I can't figure out the second step - carry the appropriate count into each new data frame along with the habitat column (and others not shown above). I am hoping to keep this automated as it's possible there could be many more than 9 counts.