简体   繁体   中英

assign vector at x, y coordinates of a matrix in R

I am moving from MATLAB to R and have a question regarding how to assign a vector at x , y coordinates of a matrix. For this, I tried with defining an array and then reading each pixel. I am stuck with reassigning values to the matrix after processing it. Following is my code:

GR_anom<-array(NaN,dim=c(180,360,100))
for (i in 1:180)) {
  for (j in 1:360) {
    GR_vec<-as.data.frame(GR[i,j,,drop=TRUE])
    Nonses= seasonaltrend(GR_vec,2002,2017)
    GR_anom[i,j,] <- Nonses[1]
  }
}

The line(GR_anom[i,j,] <- Nonses[1]) is written in the MATLAB format but in R it seems to work differently. I am stuck here since long in it, can you please suggest?

I have resolved the problem. The issue was the variable 'Nonses' is a list and therefore cannot be assigned to an array. In matlab everything is a matrix, so didn't think in that direction. Thank you very much for your responses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM