An update, I have been able to automate the MannKendall test and capture the 
output into a .txt file:

lat<-seq(-125,-67,0.5)
lon<-seq(25,53,0.5)

fun.mk<-function(x){
        for (i in 1:length(lat)){
                for (j in 1:length(lon)){
                        v<-rev(extract(x,SpatialPoints(cbind(lat[i],lon[j]))))
                        mk<-MannKendall(v)
                        pv<-mk$sl
                        out<-data.frame(cbind(lat[i],lon[j],pv[1]))
                        
write.table(out,"myraster.mk.txt",append=TRUE,col.names=FALSE,row.names=FALSE,quote=FALSE)
                        }}}
myraster.mk<-fun.mk(myraster)

Now, I would like to read that file back into R as a RasterLayer. So far, I can 
read it in as a table to get:

myraster.table<-read.table("myraster.mk.txt",header=FALSE) 
myraster.table
        V1     V2          V3
1  -86.000 35.000 0.071539655
2  -86.000 35.125 0.004216323
3  -86.000 35.250 0.449751556
4  -86.000 35.375 0.124644011
5  -86.000 35.500 0.128179774
…

In the Raster package, there is "as.data.frame" to go from raster->data.frame 
but I can't find anything to go in the opposite direction, data.frame->raster. 
I tried using "as.raster", but that didn't work:

myraster.raster<-as.raster(myraster.table)
Error in UseMethod("as.raster") : 
  no applicable method for 'as.raster' applied to an object of class 
"data.frame"

Thanks,
Tiffany
On Aug 1, 2012, at 6:24 PM, Tiffany Smith wrote:

> Hello,
> 
> I'm trying to do a Mann-Kendall test on my RasterBrick data. So far, I've 
> been able to complete the Mann-Kendall test (via the "Kendall" package) by 
> extracting a series like so:
> 
> onelocation<-rev(extract(myraster,SpatialPoints(cbind(-86,33))))
> onelocation.mk<-MannKendall(onelocation)
> 
> I need help either figuring out a way to do the MK test with raster data, or 
> if I loop through all points and use the above commands, how can I return 
> that data into a Raster so I can visualize the results by making maps?
> 
> Thanks,
> Tiffany


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to