title: Looping through a 3-d array and creating subset vectors in R
body: <p>I have the following MWE:</p>
  
  <pre><code>N &lt;- 84 #Number of datasets to pull data from
  dates &lt;- c("2010.01", "2010.02", "2010.03", "2010.04", "2010.05", "2010.06", "2010.07", "2010.08",
   "2010.09", "2010.10", "2010.11", "2010.12", "2011.01", "2011.02", "2011.03", "2011.04", "2011.05",
   "2011.06", "2011.07", "2011.08", "2011.09", "2011.10", "2011.11", "2011.12", "2012.01", "2012.02",
   "2012.03", "2012.04", "2012.05", "2012.06", "2012.07", "2012.08", "2012.09", "2012.10", "2012.11",
   "2012.12", "2013.01", "2013.02", "2013.03", "2013.04", "2013.05", "2013.06", "2013.07", "2013.08",
   "2013.09", "2013.10", "2013.11", "2013.12", "2014.01", "2014.02", "2014.03", "2014.04", "2014.05",
   "2014.06", "2014.07", "2014.08", "2014.09", "2014.10", "2014.11", "2014.12", "2015.01", "2015.02",
   "2015.03", "2015.04", "2015.05", "2015.06", "2015.07", "2015.08", "2015.09", "2015.10", "2015.11",
   "2015.12", "2016.01", "2016.02", "2016.03", "2016.04", "2016.05", "2016.06", "2016.07", "2016.08",
   "2016.09", "2016.10", "2016.11", "2016.12") #list of all dates to loop through
  
  A &lt;- list()
  for (k in seq_along(dates)) {
    A[[k]] &lt;- read_excel(paste0("~/R/data.", dates[k], ".xlsx"), range = "B3:EO94")
  }
  data &lt;- array(unlist(A), dim=c(91,144,84)) #3-dimensional array
  
  ####Problem here####
  countries &lt;- c("Can", "US")
  coord &lt;- c("15,34", "23,28")
  
  long &lt;- c("34", "28")
  lat &lt;- c("15", "23")
  
  for (c in seq_along(countries)) {
  for (i in seq_along(lat)) {
  for (j in seq_along(long)) {
    nam &lt;- sprintf("ci%d%d", c, i)
    assign(nam, data[i,j,])
  }}}
  </code></pre>
  
  <p>I am basically trying to create two vectors that I could write individually as <code>Can &lt;- data[15,34,]</code> and <code>US &lt;- data[23,28,]</code>. My problem lies in me wanting to try and write data[[x,y],] to recognize the the comma within the looped value. I was wondering if there was a way around this? I don't think having a separate <code>i</code> and <code>j</code> to loop through would work because it would make 4 variables no?</p>
  
  <p>I could do them individually but I have nearly 100 countries to do this for, as such, I look towards loops.</p>