Waaw Oscar!

Thanks a lot! I really appreciate his! Also the way you drop the regions
that I don't need is very interesting for me since I did it way more
lengthy!

Also thanks again for all of you who answered this question!

Best and good luck with your research!

Janka



2014-07-03 23:10 GMT+02:00 Oscar Perpiñan <oscar.perpinan@upm.es>:

> Hi,
>
> I propose the code below to solve your problem. By the way, I have
> found your shapefiles here:
> https://github.com/briatte/kmaps/tree/master/maps/regions.
>
> Best,
>
> Oscar.
>
> library(sp)
> library(maptools)
>
> nuts <- readShapePoly(fn="NUTS_RG_60M_2006")
>
> ## no data provided, so I have to produce a toy example
> someNuts <- sample(nuts$NUTS_ID, 300)
> Alldata <- data.frame(nuts3 = someNuts, MEt = rnorm(6000))
> Value <- aggregate(MEt ~ nuts3, data = Alldata, FUN = mean)
> names(Value) <-  c("NUTS_ID","ValueMEt")
>
> ## Match polygons with data
> idx <- match(nuts$NUTS_ID, Value$NUTS_ID)
> ## Places without information
> idxNA <- which(is.na(idx))
> ##Information to be added to the SpatialPolygons object
> dat2add <- Value[idx, ]
> ## spCbind uses row names to match polygons with data
> ## First, extract polygon IDs
> IDs <- sapply(nuts@polygons, function(x)x@ID)
> ## and join with the SpatialPolygons
> row.names(dat2add) <- IDs
> datPols <- spCbind(nuts, dat2add)
> ## Drop those places without information
> datPols <- datPols[-idxNA, ]
>
> ## Display variable using 'spplot'
> spplot(datPols["ValueMEt"])
>
> -----------------------------------------------------------------
> Oscar Perpiñán Lamigueiro
> Dpto. Ingeniería Eléctrica (ETSIDI-UPM)
> Grupo de Sistemas Fotovoltaicos (IES-UPM)
> URL: http://oscarperpinan.github.io
> Twitter: @oscarperpinan
>

	[[alternative HTML version deleted]]

