this.year<-2014
x<-this.year-1
y<-this.year-2
x.s<-x-2000
y.s<-y-2000
tpop_y.s<-acs.fetch(endyear=x,span=1,geography=mystates,variable="B01003_001", col.names="DM_TPOP_x.s")
tpop_x.s<-acs.fetch(endyear=y,span=1,geography=mystates,variable="B01003_001",col.names="DM_TPOP_y.s")
I'm using the package acs to pull out data from the American community survey to update an infographics website. I hope to run the code every year by inputing the current year in this.year and having the code update data for the past 2 years, x and y.
If this.year is 2015, x is 2014, x.s is 14, y is 2013, y.s is 13. The end result I want is (for y) the data frame name tpop_13 with the column name DM_TPOP_13. (for x) the data frame name tpop_14 with the column name DM_TPOP_14.
The code is pulling the desired data correctly, but this code returns (for y) the data frame name tpop_y.s with the column name DM_TPOP_y.s. (for x) the data frame name tpop_x.s with the column name DM_TPOP_x.s.
I tried searching for similar questions and found this one: How to print R variables in middle of String
I tried applying the answer by using the quotes \"',x.s,'\" to solve my problem, but it doesn't work. The code returns (for x) the column name DM_TPOP_...x.s.... I understand that R does not evaluate any expression within the quotes - it just prints the string you defined. But how can you get around this problem so that there can be a variable in a string?
Help would be greatly appreciated!