I have the following code example:
library(readxl)
library(tidyverse)
N <- 5 #number of datasets to pull data from
ind <- c("2010", "2011", "2012", "2013", "2015")
A <- array(rep(1, 91*144*5), dim=c(91,144,5))
for (k in seq_along(ind)) {
A <- read_excel(paste0("~R/data", ind[k], ".xlsx"), range="B3:EO94")
}
I know that this is not reproducible due to inability to upload data. The above code captures my thought process in what I am trying to do. I want to create a matrix A(i,j,k) where i and j are rows and columns, respectively, from the k excel files. So in my case, k is the years in ind. I have those 5 excel files and they have identical dimensions.
What I want out of this process is the ability to take a particular set of i,j and create a new vector that has a length=k, although this is not the question I am asking here. For context, i and j are longitude and latitude and k is year.
Aeach time, when you want A to be a 3D array receiving a different 2D slice in each cycle of the loop. So you should declareAas a 91 * 150(ish) * 5 array ahead of the loop, change the for tofor(k in seq_along(ind)), changeAtoA[,,k]and"~R/data[k]"topaste0("~R/data", ind[k])