0

I have R script as shown below and has error

  areaw=matrix(0,nrow=2592,ncol = 1647)
  dim(areaw)
 [1] 2592 1647
 # 
 areaw[,1]=temp[,1]
 areaw[,2]=temp[,2]
 #
 dim(temp)
 [1] 2592    2
 #
 for(j in 3:1647) {for (i in 1:2592) {if(temp[i,j]> -290.0) {areaw[i,j]=veca[i]} }}
 Error in temp[i, j] : subscript out of bounds

then How can I fix the subscript out of bounds error? Thank you very much in advance for your time

  • If `temp` has dimensions of 2592 by 2, then the first iteration–`i = 1` and `j = 3` will not work for `temp`. There is no `temp[1, 3]`. What is in `veca`? When is `temp` created? It looks like you're new to SO; welcome to the community! If you want great answers quickly, it's best to make your question reproducible. This includes sample data like the output from `dput(head(dataObject)))` and any libraries you are using. Check it out: [making R reproducible questions](https://stackoverflow.com/q/5963269). – Kat Mar 16 '22 at 00:02

0 Answers0