Skip to content
Prev 18915 / 29559 Next

Read .dat file as raster

Thiago, it would be useful the mention the source (I am guessing CRU),
as others might then benefit from this discussion. Perhaps the below
does it (I have not checked this):

f <- 'ccld6190.dat'
d <- readLines(f)
d <- d[-c(1:2)]
d <- lapply(d, function(r) lapply(0:719, function(i) substr(r, i*5+1,(i+1)*5)))
d <- as.numeric(unlist(d))
d[d==-9999] <- NA
d <- matrix(d, ncol=12)

library(raster)
b <- brick(xmn=0, xmx=360, nl=12)
res(b) <- 0.5
values(b) <- d
b <- rotate(b)

Robert

On Mon, Jul 22, 2013 at 7:41 AM, Thiago V. dos Santos
<thi_veloso at yahoo.com.br> wrote: