sk_add_bins: Add bin labels to a variogram data frame

View source: R/sk_sample.R

sk_add_binsR Documentation

Add bin labels to a variogram data frame

Description

Helper function for grouping the rows of input data frame vg into n_bins bins according to the value of the (numeric) distance column d. This uses either base::cut or, if probs is supplied, stats::quantile.

Usage

sk_add_bins(vg, n_bin = 25, probs = NULL)

Arguments

vg

data frame with numeric column 'd'

n_bin

integer number of distance bins to assign

probs

numeric vector of quantile probabilities to establish breakpoints (length n_bin+1)

Details

By default, the function sets probs to a sequence of length 1+n_bin evenly splitting the interval [0,1] to ensure approximately equal sample sizes for each bin. Setting probs=NA instead sets the bin endpoints such that the range of distances is split evenly (note this may produce empty bins)

The function is called by sk_sample_vg and sk_plot_semi (when column bin is missing). It can also be used to recompute bins after an rbind of multiple variogram data frames.

Value

same as input vg but with integer column bin added/modified

See Also

Other variogram functions: sk_vario_fun()

Examples

distance_df = data.frame(d=runif(25))
sk_add_bins(distance_df)

# specify fewer bins and set up quantiles explicitly
sk_add_bins(distance_df, n_bin = 5) # same as ...
sk_add_bins(distance_df, n_bin = 5, probs=seq(0, 1, length.out=6))

# break range of distances into evenly spaced bins (of varying sample sizes)
sk_add_bins(distance_df, n_bin = 5, probs=NULL)


snapKrig documentation built on May 31, 2023, 6:34 p.m.