[R-sig-Geo] Calculate new value with area from the according polygon without merging data frames

Bernd Vogelgesang bernd.vogelgesang at gmx.de
Fri Feb 13 13:05:34 CET 2015


Dear list,
this is likely to be more a "normal" R question, but as it has also to a  
little with spatial stuff, I dare to ask here.

I have a data frame "df" with column POLYID and column TIME and also a  
SpatialPolygonsDataFrame "Shape" also with a column POLYID.
Now I would like to calculate a new column PRESENCE with TIME /  
area(Shape) where the POLYID's from both data frames are matched.

It's easy to do this simply by merging the data frames and then do the  
calculation, but I would like to learn how to avoid to bloat my data  
frames always with columns for a one-time-usage and then delete them  
again. I know/hope there must be a simple way to lookup values from  
another data frame, but did not succeed so far.

Already tried  multiple ways, e.g. sth like

df$PRESENCE <- df$TIME / area(Shape[subset(Shape at data,POLYID %in%  
df$POLYID)])

but, ... nothing works so far.

Any help appreciated.

Cheers
Bernd

p.s. sorry for not delivering a reproducible example, but for "experts",  
the problem might be obvious nevertheless.
-- 
Bernd Vogelgesang
Siedlerstraße 2
91083 Baiersdorf/Igelsdorf
Tel: 09133-825374



More information about the R-sig-Geo mailing list