Having two rasters (values are floats with 5 decimals) with the same dimensions. The code given below makes one file out of two rasters r and r1. If r is bigger,put blue ,otherwise put red.
This code worked well but I was asked to add another condition. How this code works:
If r is 0.229 and r1 is 0.228 then r is bigger(notice third decimal). what I need is to specify the first two decimals for example:
r= 0.228 r1=0.224 put yellow colour(they are rather similar)
r= 0.238 r1=0.224 put blue colour(r is bigger)
r= 0.128 r1=0.224 put red colour(r is lower)
1- to read the first file r
conn <- file("C:\\corr.bin","rb")
corr<- readBin(conn, numeric(), size=4, n=1440*720, signed=TRUE)
2- to read the second file r1:
conne <- file("C:\\cor06.bin","rb")
over<-readBin(conne, numeric(), size=4, n=1440*720, signed=TRUE)
calculate:
r <-raster(t(matrix((data=corr), ncol=720, nrow=1440)))
r1 <- raster(t(matrix((data=over), ncol=720, nrow=1440)))
m <- r > r1 #Compare the two rasters
image( m , col = c("blue" , "red" ) )