spCbind-methods: cbind for spatial objects

Description Methods Author(s) See Also Examples

Description

spCbind provides cbind-like methods for Spatial*DataFrame objects in addition to the $, [<- and [[<- methods already available.

Methods

obj = "SpatialPointsDataFrame", x = "data.frame"

cbind a data frame to the data slot of a SpatialPointsDataFrame object

obj = "SpatialPointsDataFrame", x = "vector"

cbind a vector to the data slot of a SpatialPointsDataFrame object

obj = "SpatialLinesDataFrame", x = "data.frame"

cbind a data frame to the data slot of a SpatialLinesDataFrame object; the data frame argument must have row names set to the Lines ID values, and should be re-ordered first by matching against a shared key column

obj = "SpatialLinesDataFrame", x = "vector"

cbind a vector to the data slot of a SpatialLinesDataFrame object

obj = "SpatialPolygonsDataFrame", x = "data.frame"

cbind a data frame to the data slot of a SpatialPolygonsDataFrame object; the data frame argument must have row names set to the Polygons ID values, and should be re-ordered first by matching against a shared key column

obj = "SpatialPolygonsDataFrame", x = "vector"

cbind a vector to the data slot of a SpatialPolygonsDataFrame object

Author(s)

Roger Bivand

See Also

spChFIDs-methods, spRbind-methods

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], 
  IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
library(foreign)
xtra <- read.dbf(system.file("share/nc_xtra.dbf", package="maptools")[1])
o <- match(xx$CNTY_ID, xtra$CNTY_ID)
xtra1 <- xtra[o,]
row.names(xtra1) <- xx$FIPSNO
xx1 <- spCbind(xx, xtra1)
names(xx1)
identical(xx1$CNTY_ID, xx1$CNTY_ID.1)

Example output

Loading required package: sp
Checking rgeos availability: FALSE
 	Note: when rgeos is not available, polygon geometry 	computations in maptools depend on gpclib,
 	which has a restricted licence. It is disabled by default;
 	to enable gpclib, type gpclibPermit()
Warning message:
readShapePoly is deprecated; use rgdal::readOGR or sf::st_read 
 [1] "AREA"      "PERIMETER" "CNTY_"     "CNTY_ID"   "NAME"      "FIPS"     
 [7] "FIPSNO"    "CRESS_ID"  "BIR74"     "SID74"     "NWBIR74"   "BIR79"    
[13] "SID79"     "NWBIR79"   "CNTY_ID.1" "east"      "north"     "L_id"     
[19] "M_id"      "names"    
[1] FALSE

maptools documentation built on Sept. 7, 2021, 5:09 p.m.