I want to change the name of the data frame using the specific value I get from the data's name. My data comes from the World Bank's Open Data initiative.
My code:
library(readxl)
API_SP_POP_TOTL_DS2_en_excel_v2_3358348 <- read_excel("API_SP.POP.TOTL_DS2_en_excel_v2_3358348.xls", sheet = "Data", skip = 3)
colnames(API_SP_POP_TOTL_DS2_en_excel_v2_3358348) <- sub(" ", "", colnames(API_SP_POP_TOTL_DS2_en_excel_v2_3358348))
indicatorName <- API_SP_POP_TOTL_DS2_en_excel_v2_3358348$IndicatorCode[1]
varName = gsub(".", "", indicatorName, fixed=TRUE)
And then, I want to assign the varName (in this case, varName is SPPOPTOTL) as the name of the Data because it is API_SP_POP_TOTL_DS2_en_excel_v2_3358348, so long.
In short, I want to get this result.
SPPOPTOTL <- API_SP_POP_TOTL_DS2_en_excel_v2_3358348
I do not want to type in the varName, SPPOPTOTL, directly.
assign.