[R] can't vectorize an expression

Robin Hankin r.hankin at auckland.ac.nz
Wed Dec 12 04:44:22 CET 2001


Dear R support network

I have a problem that is driving me crazy.

I have a dataframe with about 74000 landscapes which I call "land".  A
landscape is a 2km -by- 2km square.

Land has three columns: land$lat, land$long, and land$description.
The last one holds a NON-unique (integer) description of each
landscape.  There are maybe 100 distinct descriptions.  Identifying
landscapes that have identical descriptions gives equivalence classes.

I am interested in the largest few equivalence classes (that is, a
*large* set of landscapes with identical descriptions).  The largest
equivalence class holds around 1500 landscapes.


Thus:

top <- rev(sort(table(land$description)))
top.values  <- as.numeric(names(top))

So far so good: top.values holds the descriptions of the largest
equivalence classes first.

Now things turn to custard; the following lines show the only way I
could think of to extract the six largest equivalence classes:

which(land$description == top.values[1]) -> biggest1
which(land$description == top.values[2]) -> biggest2
which(land$description == top.values[3]) -> biggest3
which(land$description == top.values[4]) -> biggest4
which(land$description == top.values[5]) -> biggest5
which(land$description == top.values[6]) -> biggest6 

plotting them is relatively easy:

plot(b[,1:2],pch=16,cex=0.2)
matplot(land$lat[biggest1],land$long[biggest1], col="red",   type="p",pch=16,add=TRUE)
matplot(land$lat[biggest2],land$long[biggest2], col="blue",  type="p",pch=16,add=TRUE)
matplot(land$lat[biggest3],land$long[biggest3], col="yellow",type="p",pch=16,add=TRUE)
matplot(land$lat[biggest4],land$long[biggest4], col="green", type="p",pch=16,add=TRUE)
matplot(land$lat[biggest5],land$long[biggest5], col="purple",type="p",pch=16,add=TRUE)
matplot(land$lat[biggest6],land$long[biggest6], col="cyan",  type="p",pch=16,add=TRUE)


QUESTION: How do I vectorize this?

--


A test dataset might look like


lat long description
 172.1100 -34.1500 8
 172.1300 -34.1500 8
 172.1500 -34.1500 8
 172.1300 -34.1700 8
 172.1500 -34.1700 7
 173.0100 -34.3900 7
 173.0300 -34.3900 6
 172.8700 -34.4100 7
 172.8900 -34.4100 7
 172.9700 -34.4100 6
 172.9900 -34.4100 8
 173.0100 -34.4100 8
 173.0300 -34.4100 8
 173.0500 -34.4100 8
 172.6700 -34.4300 8
 172.6900 -34.4300 6
 172.7100 -34.4300 6
 172.7300 -34.4300 6
 172.7500 -34.4300 6
		   

-- 

Robin Hankin, Lecturer,
School of Environmental and Marine Science
Private Bag 92019 Auckland
New Zealand

r.hankin at auckland.ac.nz
tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list