[R] Aggregating spatial data

IOANNA ii54250 at msn.com
Tue Nov 26 13:02:27 CET 2013


Fantastic. Thanks very much! Is there an easy  way to plot the points and
the 4 areas?

Best, 
Ioanna

-----Original Message-----
From: David Carlson [mailto:dcarlson at tamu.edu] 
Sent: 25 November 2013 15:21
To: 'IOANNA'; r-help at r-project.org
Subject: RE: [R] Aggregating spatial data

Something like this?

> s <- expand.grid(x=seq(1,100,by=1),y=seq(1,100,by=1))
> w <-
data.frame(x=s$x,y=s$y,z1=rep(c(1,2,3,4),times=length(s$x/4)),
+   z2=seq(1,length(s$x),by=1))
> w$EW <- cut(w$x, breaks=c(.5, 50.5, 100.5), labels=c("West",
"East"))
> w$NS <- cut(w$y, breaks=c(.5, 50.5, 100.5), labels=c("South",
"North"))
> aggregate(z1~EW+NS, w, table)
    EW    NS z1.1 z1.2 z1.3 z1.4
1 West South 2600 2600 2400 2400
2 East South 2400 2400 2600 2600
3 West North 2600 2600 2400 2400
4 East North 2400 2400 2600 2600
> table(w$z1)

    1     2     3     4 
10000 10000 10000 10000 
> aggregate(z2~EW+NS, w, mean)
    EW    NS     z2
1 West South 2475.5
2 East South 2525.5
3 West North 7475.5
4 East North 7525.5

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of IOANNA
Sent: Monday, November 25, 2013 8:46 AM
To: r-help at r-project.org
Subject: [R] Aggregating spatial data
Importance: High

Hello all, 

 

I have a data frame in the form:

 

s<-expand.grid(x=seq(1,100,by=1),y=seq(1,100,by=1))

w<-data.frame(x=s$x,y=s$y,z1=rep(c(1,2,3,4),times=length(s$x/4))
,z2=seq(1,le
ngth(s$x),by=1))

 

The w$x and w$y represent the location of points and z1 and z2 attributes
corresponding to these points. 

 

 

My question is how to divide this area in 4 sub-areas of equal points each
and produce the counts of z1= '1', '2' , '3' in each quarter as well as mean
values of z2 for each quarter. 

 

Best, 

Ioanna


	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org 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.



More information about the R-help mailing list