PCA using raster datasets in R

后端 未结 6 1682
别那么骄傲
别那么骄傲 2021-01-18 10:48

I have several large rasters that I want to process in a PCA (to produce summary rasters). I have seen several examples whereby people seem to be simply calling prcomp or pr

6条回答
  •  轮回少年
    2021-01-18 10:59

    here is a working solution:

    library(raster) 
    filename <- system.file("external/rlogo.grd", package="raster")
    r1 <- stack(filename) 
    pca<-princomp(r1[], cor=T)
    res<-predict(pca,r1[])    
    

    Display result:

    r2 <- raster(filename) 
    r2[]<-res[,1]
    plot(r2)
    

提交回复
热议问题