I am pretty ok with loops in Stata and I am trying to program something similar in R, but I keep getting error messages- any idea why this loop doesnt work?
I have an Excel sheet with data with separate tabs for each month (as in monthlist). I want to import each separate tab and add year and month column to it.
monthlist = list("Jan", "Feb", "Mar", "Apr", "May", "June", "Jul", "Aug",
"Sep", "Oct", "Nov", "Dec")
for (k in seq_along(monthlist)){
infile <- paste(i, " GP",".xlsx",sep=""); name<-
paste("X",i,"_GP",sep="")
name.[k]<- read_excel(infile, sheet = [k])
month=[k]
name.[k] = cbind(year, month, name.[k])
}
I have tried and tried researching the correct reference to k values, but I cant figure it out. Please help.