title: Filling an array by row with a sequence of numbers in r
body: <p>I am working in program r and need help with writing some code. I have a 50 by 3 by 8 dimensional array. Most cells in this array are zero, but some are NA. I need to replace the zeroes in the array with a sequence of numbers such that all cells in a row have the same number. The sequence starts at 1 and runs to total number of rows in the array. Also, the NAs must remain, so cells with NAs cannot be overwritten. Further, some rows are all NAs and so the row sequence will not be exactly 400 (50 x 8), but something less. I have found information on how to address each part of this problem, but am struggling to put all the pieces together in a way that works. I greatly appreciate your help writing this r code.
  <br>Example, for this array:
  <br>y&lt;-array(0,dim=c(10,3,2))
  <br>#add NAs
  <br>y[4,2:3,1]&lt;-NA
  <br>y[8,1:3,1]&lt;-NA
  <br>y[10,1:3,2]&lt;-NA
  <br>I need to replace the 0's with a sequence such that the first matrix in the array has its rows numbered 1 to 9 (all cells in row 1=1, 2=2, and so on, with NAs left in place). Matrix 2 would have rows numbered 10 to 18.</p>