[R] Matrix or grid conversion of spatial data

Charles C. Berry cberry at tajo.ucsd.edu
Thu Apr 19 02:22:27 CEST 2007


On Wed, 18 Apr 2007, Marco Visser wrote:

> Dear Happy R-users & experts,
>
> I am in need of advice,
> While working with spatial data (x & y coordinates of seed locations) I have come accross the problem that I need to convert my point data into a matrix or grid system. I then need to count how often a point falls into a certain position in the matrix or grid. I have searched all day online, asked collegeas but nothing works.
>
> Sadly my R "box of tricks" has run out.
>
> My (point) data looks like this;
>
> x         y
> 2.3    4.5
> 3.4      0.2
>
> and continues for another million records.
>
> Now my question; is there any function that is able to "count" how often 
> a point falls into a grid based on the x and y location? So I need to 
> discretize the spatial locations to a regular grid and then counting how 
> often a point occurs.

see
 	?table
and
 	?cut

Maybe something like

 	x.breakpoints <- <sensible breakpoints for x>
 	y.breakpoints <- <sensible breakpoints for y>

 	my.grid <- table(
 			 cut( x, x.breakpoints ),
 			 cut( y, y.breakpoints ) )


see also ?xtab and  ?quantile


>
> Many thanks for your thoughts on this problem.
>
> Marco Visser
>
>
>
>
>
>
>
>
>
> __________________________________________________
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> 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.
>

Charles C. Berry                        (858) 534-2098
                                          Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	         UC San Diego
http://biostat.ucsd.edu/~cberry/         La Jolla, San Diego 92093-0901



More information about the R-help mailing list