[R] Raster Help
John Kane
jrkrideau at inbox.com
Fri Feb 20 17:06:54 CET 2015
Simon,
You missed a key request from Sven. He asked for data in dput() format. This is essential for dealing with many problems. Do ?dput for info on the function but esssentially it let's the reader see your data exactly as you see it, unfazed buy any special setting the reader may have for reading in data on R.
Here is a little example of dput output. Just copy and paste into to get the new data.frame "dat".
dat1 <- structure(list(Observation = c("A", "B", "C", "D", "E", "F",
"G", "H"), Participant.ID = c(1L, 1L, 2L, 3L, 3L, 4L, 4L, 5L),
Video.Coder = c("Donald", "Tracy", "Donald", "Sam", "Tracy",
"Donald", "Tracy", "Sam"), Score = c(4L, 5L, 6L, 2L, 3L,
2L, 1L, 8L)), .Names = c("Observation", "Participant.ID",
"Video.Coder", "Score"), class = "data.frame", row.names = c(NA,
-8L))
See these for some hints on asking questions.
https://github.com/hadley/devtools/wiki/Reproducibility
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
John Kane
Kingston ON Canada
> -----Original Message-----
> From: simon.tarr at adtrak.co.uk
> Sent: Fri, 20 Feb 2015 15:45:04 +0000
> To: sven.templer at gmail.com
> Subject: Re: [R] Raster Help
>
> Hi Sven,
>
> Many thanks for the reply and my apologies for not posting any code. So
> far, I have been able to write this (but it's very basic and just getting
> me to the 'complicated' stage).
>
> setwd("C:\\Users\\simon.tarr\\Documents\\GIS\\Test Data")
> require(raster)
> require(rgdal)
> revenue<-read.table("revenue.csv",header=T,row.names=1,sep=",")
> postcodes<-raster("C:\\Users\\simon.tarr\\Documents\\GIS\\Test
> Data\\rasters\\postcodes\\postcodes.img")
> trim(postcodes)
> plot(postcodes)
>
> I have attached a .csv file that contains my revenue data (this is
> actually
> just made up data- I wanted to make sure I could get the mapping to work
> before I start handling large quantities of real data).
>
> As I mentioned, the raster contains the same list of postcode names that
> appear in the CSV. So I need to somehow 'attach' the revenue figures to
> each postcode in the raster and then plot this.
>
> I hope this makes sense and apologies for the loose language...it's the
> only way I can think of to describe it.
>
> I'm trying hard to learn R and its syntax but sometimes I get stuck. I
> often know what needs to be done but struggle to write the necessary code
> to make it happen.
>
> All the best,
>
> Simon
>
> On 19 February 2015 at 20:37, Sven E. Templer <sven.templer at gmail.com>
> wrote:
>
>> Without (example) code it is hard to follow... use ?dput to present
>> some data (subset).
>> But if it is data.frames you are dealing with (for sure with read.csv,
>> but not so sure at all with raster maps), give this a try:
>>
>> ?merge
>>
>> On 19 February 2015 at 17:44, Simon Tarr <simon.tarr at adtrak.co.uk>
>> wrote:
>>> Hello everyone,
>>>
>>> I need a little help with some R syntax to complete what (I think) is a
>>> fairly straightforward task- hopefully someone can assist!
>>>
>>> I have a raster map of the UK which is split into postcode areas (e.g.
>> DE,
>>> NG, NR etc. 127 postcodes in total).
>>>
>>> I have installed the package 'raster' and have successfully plotted the
>>> .img in R. All working and looks correct with the raster.
>>>
>>> I also have a comma delimited CSV file containing the same postcodes as
>> the
>>> raster with another column next to it containing revenue for each
>> postcode.
>>>
>>> *I was wondering if someone could help me merge/bind the revenue
>>> figures
>>> into the correct postcode in the raster so that I can plot revenue per
>>> postcode.*
>>>
>>> I feel I should be using cbind and reclassify to do this but I can't be
>>> sure.
>>>
>>> Any help would be appreciated. Thanks in advance!
>>>
>>> Simon
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
More information about the R-help
mailing list