[R] merging tables by columns AND rows

Roger Bivand Roger.Bivand at nhh.no
Thu Sep 7 14:33:21 CEST 2006


On Thu, 7 Sep 2006, isidora k wrote:

> Hi everyone!
> I have 100 tables of the form:
> XCOORD,YCOORD,OBSERVATION
> 27.47500,42.52641,177
> 27.48788,42.52641,177
> 27.50075,42.52641,179
> 27.51362,42.52641,178
> 27.52650,42.52641,180
> 27.53937,42.52641,178
> 27.55225,42.52641,181
> 27.56512,42.52641,177
> 27.57800,42.52641,181
> 27.59087,42.52641,181
> 27.60375,42.52641,180
> 27.61662,42.52641,181
> ..., ..., ...
> with approximately 1000000 observations for each. All
> these tables have the same xcoord and ycoord and I
> would like to get a table of the form
> XCOORD,YCOORD,OBSERVATION1,OBSERVATION2,... 
> 27.47500,42.52641,177,233,...
> 27.48788,42.52641,177,345,...
> 27.50075,42.52641,179,233,...
> 27.51362,42.52641,178,123,...
> 27.52650,42.52641,180,178,...
> 27.53937,42.52641,178,...,...
> 27.55225,42.52641,181,...
> 27.56512,42.52641,177,...
> 27.57800,42.52641,181,...
> 27.59087,42.52641,181,...
> 27.60375,42.52641,180,...
> 27.61662,42.52641,181,...
> In other words I would like to merge all the tables
> taking into account the common row names of their
> xcoords AND ycoords.

Your data look very much like a rectangular grid. If you had either posted
from an identifiable institution or included an informative signature,
then we'd have known which field you're in, so the following is guesswork.

If all of your data is for a full grid, with the same coordinates always
in the same order, any missing values fully represented in the data, then
reading the first data set in as a data.frame or matrix, and converting it
to a SpatialGridDataFrame object (defined in the sp contributed package)
will give you a base to start from. 

>From that you just add columns, one column for each data set, by reading
in just the data you need (for example using scan). This depends crucially
on the same grid being used each time, with the data in the same order. If
the coordinates differ between data sets, bets are off.

If these are spatial data, please consider the R-sig-geo mailing list for 
more targetted help.

> Is there any way to do this in R?
> I would be grateful for any advice.
> Many Thanks
> Isidora
> 
> ______________________________________________
> 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.
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-help mailing list