-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunPCA_Transpose_ShortCode.R
More file actions
37 lines (23 loc) · 1.1 KB
/
Copy pathRunPCA_Transpose_ShortCode.R
File metadata and controls
37 lines (23 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#EOF analysis on raster data
rm(list=ls())
island_list<-c("ka_","oa_","ma_","bi_")
seas_list<-c("djf_","mam_","jja_","son_")
for (i in 1:4) {
isl<-island_list[i]
setwd("C:/Work/AbbyF/Oliver/raster_txtfiles/")
coords<-read.table(paste(isl,"coords.txt",sep=""), header=T)
for (j in 1:4) {
seas<-seas_list[j]
setwd("C:/Work/AbbyF/Oliver/raster_txtfiles/")
rasters<-read.table(paste(isl,seas,"rasters_all.txt",sep=""),header=T)
rasterT<-t(rasters)
raster.pr<-prcomp(rasterT,center=T,scale=T)
setwd("C:/Work/AbbyF/Oliver/PC_outputs_R_T/")
prmatrix <- rasterT%*%raster.pr$rotation
spatial<-data.frame(cbind(coords,raster.pr$rotation))
#rotation is now spatial series - tack on coordinates so this file can be mapped...
write.table(prmatrix, file = paste(isl,seas,"timeseries.csv",sep=""), sep = ",")
write.table(spatial[,1:12], file = paste(isl,seas,"spatial_pr.csv",sep=""), sep = ",", col.names = T,row.names=F)
write.table(raster.pr$sdev, file = paste(isl,seas,"sdev_pr.csv",sep=""), sep = ",")
}
}