Skip to contents

colbind() adds columns to the data table of a GVector. You can combine multiple a GVector's data table with data.frames, data.tables, matrices, or the data table(s) from other GVector(s). To combine two GVectors, see rbind().

Usage

# S4 method for class 'GVector'
colbind(x, ...)

Arguments

x, ...

The first argument must be a GVector. Subsequent arguments can be data.frames, data.tables, matrices, or GVectors. Only the data tables of subsequent GVectors are added to the table in x; the geometries are ignored.

Value

A GVector.

See also

rbind(), addTable<-, dropTable()

Examples

if (grassStarted()) {

# Setup
library(sf)

# Rivers vector
madRivers <- fastData("madRivers")

# Convert sf to a GVector
rivers <- fast(madRivers)

# Convert GVector to data.frame or data.table
as.data.frame(rivers)
as.data.table(rivers)

# Subset rivers vector
rivers1 <- rivers[1:2]
rivers2 <- rivers[10:11]

# Concatenate rivers
riversCombo <- rbind(rivers1, rivers2)
riversCombo

# Add columns
newCol <- data.frame(new = 1:11)
riversCol <- colbind(rivers, newCol)
riversCol

# Remove table
riversCopy <- rivers
riversCopy # has data table
riversCopy <- dropTable(riversCopy)
riversCopy # no data table

# Add a new table
newTable <- data.frame(num = 1:11, letters = letters[1:11])
addTable(riversCopy) <- newTable
riversCopy

}