Using this SO question as a starting point, if my data appears like this:
index state date Amount
2 FL 2010-06-08 0
21 FL 2010-10-08 10
6 FL 2010-08-16 30
5 GA 2010-11-25 20
9 GA 2010-01-01 0
8 CA 2011-03-06 10
12 CA 2012-03-12 10
11 CA 2012-06-21 10
15 NY 2010-01-01 30
13 NY 2010-04-06 20
How do I use the loop example from that question's highest voted answer to create data tables for export that are named based on the state value? My goal is to export each state-specific data table to csv for separate analyses. These are large datasets so prefer using data.table package.
Below is the loop from the question linked above using the iris
dataset.
iris_split <- split(iris, iris$Species)
new_names <- c("one", "two", "three")
for (i in 1:length(iris_split)) {
assign(new_names[i], iris_split[[i]])
}