Nikos:
> I need a confirmation that I am doing the NA-work-around the _right_
> way.

Sorry, I fat-fingered the Send button before. For simplicity I tried to
use small names instead of the long "original" names. Anyhow, I think
it's clear what I am doing and what the problem is.


The problem is:
> I get several NULL's in the raster maps I write back in GRASS in
> locations (=pixels) were the input raster map(s) have a NON-NULL value.

For simplicity I tried to use small names instead of the long "original"
names. Anyhow, I think it's clear what I am doing and what the problem
is.

Cheers,  Nikos

# launch grass; launch R from within grass
# load libraries and projection information
library(spgrass6); G <- gmeta6()

# load data
raw <- readRAST6 (c('a', 'b', 'c', 'd', 'e', 'f'))

# create vector pointing to values
values <- which(!is.na(r...@data$a) & !is.na(r...@data$b) & !
is.na(r...@data$c) & !is.na(r...@data$d) & !is.na(r...@data$e) & !
is.na(r...@data$f))

# get data
data <- r...@data[values, ]

# check structure
str(data)

# perform pca with prcomp(): SVD - SCALED
prcomp.data <- prcomp(data, scale=TRUE)
prcomp.data$rotation
summary(prcomp.data)

# add new columns to the original sp object #
r...@data$pc1 <- NA
r...@data$pc2 <- NA
r...@data$pc3 <- NA
r...@data$pc4 <- NA
r...@data$pc5 <- NA
r...@data$pc6 <- NA
str(raw)

# fill-in the PCs
r...@data$pc1[values] <- prcomp.data$x[,"PC1"]
r...@data$pc2[values] <- prcomp.data$x[,"PC1"]
r...@data$pc3[values] <- prcomp.data$x[,"PC1"]
r...@data$pc4[values] <- prcomp.data$x[,"PC1"]
r...@data$pc5[values] <- prcomp.data$x[,"PC1"]
r...@data$pc6[values] <- prcomp.data$x[,"PC1"]

# write grass raster maps
writeRAST6(raw, zcol=7, vname="prcomp1_0607", overwrite=TRUE)
writeRAST6(raw, zcol=8, vname="prcomp1_0607", overwrite=TRUE)
writeRAST6(raw, zcol=9, vname="prcomp1_0607", overwrite=TRUE)
writeRAST6(raw, zcol=10, vname="prcomp1_0607", overwrite=TRUE)
writeRAST6(raw, zcol=11, vname="prcomp1_0607", overwrite=TRUE)
writeRAST6(raw, zcol=12, vname="prcomp1_0607", overwrite=TRUE)

_______________________________________________
grass-stats mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-stats

Reply via email to