'Create for loop with multiple dataframes assigned to a number
my merged dataframe (merge_dat) has the header
Street Address contentvalue2015 contentvalue2016 contentvalue2017
Now I'd like to get 10 dataframes which should look like this:
Dataframe: Address 1
Header: Year Contentvalue (of Address 1)
Dataframe: Address 2
Header: Year Contentvalue (of Address 2)
.....
My code looks like this:
for (i in 1:10) {
Contentvalue <- numeric()
Address <- numeric()
Year <- rbind(c(2015), c(2016), c(2017))
assign(paste0("Contentvalue", i), rbind(merge_dat$Contentvalue2015[i], merge_dat$Contentvalue2016[i], merge_dat$Contentvalue2017[i]))
assign(paste0("Address", i), dataframe(Year, ....)}
the 4 dots in my code represent where I don't know how to continue. I'd need to tell R that I'd like to have 10 dataframes Addressi (Address1, Address2,...) that consist of the Year vector and one of the 10 Vectors Contentvaluei. So Dataframe Address1 contains Year and Contentvalue1; Dataframe Address2 contains Year and Contentvalue2; etc.
Thank you in advance :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
