[R-sig-Geo] Converting Grid to factor list
Ronnie Babigumira
rb.glists at gmail.com
Mon Jan 9 09:13:25 CET 2006
Edzer, Many thanks for this "aha...I see" moment. Most illuminating
Ronnie
Edzer J. Pebesma wrote:
> Ronnie Babigumira wrote:
>
>> Edzer
>> Many thanks. The grid was created in ArcView and exported as an ascii
>> file. I then read it in R using the read.asciigrid function in map tools
>>
>> Any ideas?
>>
>>
> Yes; the function returns an object of class SpatialGridDataFrame:
>
> > example(read.asciigrid)
>
> rd.scg> x <- read.asciigrid(system.file("external/test.ag",
> package = "sp")[1])
>
> rd.scg> class(x)
> [1] "SpatialGridDataFrame"
> attr(,"package")
> [1] "sp"
>
> rd.scg> image(x)
> > names(x)
> [1] "/home/edzer/S/library/sp/external/test.ag"
> > names(x) = "foo"
> > f = factor(round(x$foo))
> > summary(f)
> 357 394 270 310 398 294 295 303
> 307 391
> 18 18 17 17 17 16 16 16
> 16 16
> [etc., etc.,...]
> 250 256 265 274 290 291 297 299
> (Other) NA's
> 9 9 9 9 9 9 9 9
> 1938 6097
> >
>
> The renaming to foo was not necessary, but quotes would have
> been necessary around the name as it contained slashes. I rounded
> the values because they were numeric.
> --
> Edzer
>
>> Ronnie
>>
>> Edzer J. Pebesma wrote:
>>
>>
>>> Ronnie, you didn't tell us how you created the grid. Is it on of the
>>> grid classes in package sp? In that case you can address the
>>> variable in it by it's name, say foo:
>>>
>>> mygrid.f <- factor(mygrid$foo)
>>>
>>> hth,
>>> --
>>> Edzer
>>>
>>> Ronnie Babigumira wrote:
>>>
>>>
>>>> Hi listers
>>>> I would like to change a grid to a factor list so as to apply Join
>>>> Count statistics however when I use
>>>> mygrid.f <- factor(mygrid)
>>>>
>>>> I get an error message " 'x' must be atomic".
>>>>
>>>> Looking through the RHelp archives, I have chanced on emails with a
>>>> similar problem but no direct answer to this. Is anyone farmiliar
>>>> with this and how can I go about it
>>>>
>>>>
>>>> Many thanks
>>>>
>>>> Ronnie
>>>>
>>>> _______________________________________________
>>>> R-sig-Geo mailing list
>>>> R-sig-Geo at stat.math.ethz.ch
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>
>>>>
>>>>
>>>
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
>
>
More information about the R-sig-Geo
mailing list