Robert,

Thanks a lot, your code works smoothly.

This file is an excerpt of the Maxent dataset (http://www.cs.princeton.edu/~schapire/maxent/) which is based on some monthly climatic variables from IPCC.

This awkard ascii format, however (and unfortunately), is pretty common in datasets found around.
 
Greetings,
--
Thiago V. dos Santos
PhD student
Land and Atmospheric Science
University of Minnesota
http://www.laas.umn.edu/CurrentStudents/MeettheStudents/ThiagodosSantos/index.htm
Phone: (612) 323 9898


________________________________
 From: Robert J. Hijmans <r.hijmans@gmail.com>

Cc: R-SIG list <r-sig-geo@r-project.org> 
Sent: Monday, July 22, 2013 3:04 PM
Subject: Re: [R-sig-Geo] 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

> Dear all,
>
> Today I came across with a raster file formatted as ascii that looks like this: https://dl.dropboxusercontent.com/u/27700634/ccld6190.dat (17Mb)
>
> The question is: what is the best approach to read a file like this into R and convert it to a raster object?
>
>
> Thanks in advance,
> --
> Thiago V. dos Santos
> PhD student
> Land and Atmospheric Science
> University of Minnesota
> http://www.laas.umn.edu/CurrentStudents/MeettheStudents/ThiagodosSantos/index.htm
> Phone: (612) 323 9898
>         [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
	[[alternative HTML version deleted]]

