pkern_add_bins: Add bin labels to a variogram data frame

View source: R/pkern_sample.R

pkern_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

pkern_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 pkern_sample_vg and pkern_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

Examples

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

# specify fewer bins and set up quantiles explicitly
pkern_add_bins(distance_df, n_bin = 5) # same as ...
pkern_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)
pkern_add_bins(distance_df, n_bin = 5, probs=NULL)


deankoch/pkern documentation built on Oct. 26, 2023, 8:54 p.m.