I have matlab files with an integer in each name of my variables inside (except the first one). I want to loop to concatenate the name of the integers. There is my code:
library('R.matlab')
mat <- readMat('SeriesContPJM.mat')
#str(mat)
#typeof(mat)
#mat[[1]]
write.csv(mat$vol.PJM$data[[4]][[1]], "PJM.csv")
i = 2
while (i < 7)
{
write.csv(get(paste("mat$vol.PJM", as.character(i), "$data[[4]][[1]]", sep = "")), paste(paste("PJM", as.character(i), sep="_"), "csv", sep ="."))
i = i + 1
}
I have write.csv(mat$vol.PJM$data[[4]][[1]], "PJM.csv")
which gives me the good ouput. I would like the same for the other variable names in the loop but I get the following ouput:
+ Error in get(paste("mat$vol.PJM", as.character(i), "$data[[4]][[1]]", (from importpjm.R#10) :
objet 'mat$vol.PJM2$data[[4]][[1]]' introuvable
"introuvable" means "not found" in French.