I'm trying to make a loop read individual sheets from an excel file and load them into individual matrices in R. Im getting stuck on the syntax to make the loop create independent files using the counter "i". I'd like the output to be Volcano.0, Volcano.1, Volcano.2, Volcano.3 etc....
Here is what I have that doesn't work:
for (i in 0:16){
tab <- paste0("Cluster", " ", i)
Volcano.[i] <- read_excel("/MyWorksheet.xlsx", sheet = tab)
}
I tried Volcano.i but that obviously just gave me Volcano.i at the end. What am I missing here?
By the way, I suspect that the read_excel() function will a return a data frame, not a matrix. A data frame can have columns with different kinds of data but a matrix must be entirely of one data type.
I tested it it returns an error, I think it is because you are trying to assign data to the [0] element of Volcanolist?
the error specifically was:
New names:
* `` -> ...1
Error in VolcanoList[[i]] <- read_excel("/Users/Chris/Desktop/Work/Mouse/IMQ/Volcano Plot/DEGbyTreatmentIMQ-4.xlsx", :
attempt to select less than one element in integerOneIndex
If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: