stackdata: Combine 'data.frame's

stackdataR Documentation

Combine data.frames

Description

Combine data.frames

Usage

stackdata(..., fillwith = NA, keepclass = FALSE)

Arguments

...

data.frames or objects that can be coerced to data.frames

fillwith

Which value to use for missing variables. This could be a scalar, a named vector, or a named list with one value in each component; see Details.

keepclass

Whether to preserve the class of each variable. The elements in fillwith are coerced to the corresponding variable's class.

Details

This function combines data.frames by filling in missing variables. This is useful for combining data from sampled locations with prediction locations.

If fillwith is a named object, its names must correspond to the names of variables in the data frames. If a variable is missing, then it is filled with the corresponding value in fillwith. fillwith can contain only one unnamed component which corresponds to the default filling.

Value

A stacked data.frame.

Examples

## Not run: 
d1 <- data.frame(w = 1:3, z = 4:6 + 0.1)
d2 <- data.frame(w = 3:7, x = 1:5, y = 6:10)
(d12a <- stackdata(d1, d2))
lapply(d12a, class)
(d12b <- stackdata(d1, d2, fillwith = c(x = NA, y = 0, z = -99)))
lapply(d12b, class)
(d12c <- stackdata(d1, d2, fillwith = c(x = NA, y = 0, z = -99),
                   keepclass = TRUE))
lapply(d12c, class)
(d12d <- stackdata(d1, d2, fillwith = c(x = NA, 0)))

data(rhizoctonia)
predgrid <- mkpredgrid2d(rhizoctonia[c("Xcoord", "Ycoord")],
                         par.x = 100, chull = TRUE, exf = 1.2)
rhizdata <- stackdata(rhizoctonia, predgrid$grid)

## End(Not run)

geoBayes documentation built on Aug. 21, 2023, 9:08 a.m.

Related to stackdata in geoBayes...