Learn R Programming

CAWaR (version 0.0.2)

countCropCycles: countCropCycles

Description

Matches two vectors with different lengths based on their maximum value.

Usage

countCropCycles(x, min.length = c(1, 1))

Arguments

x

Target numeric vector.

min.length

Two element numeric vector.

Value

A numeric element with the number of crop cycles in x.

Details

The function counts the number of value segments in x that are above its mean effectively counting the number of crop cycles. Before reporting the final value, min.length is used to filter outliers. The first element filters segments that lie below the mean (i.e. recently cultivated/harvested). If the segment length is greater than the 1st element in min.length the segment is relabeled as "1 (i.e. "crop growth/maturity". This process is repeated for segments above the mean (i.e. crop growth/maturity). If the length of a segment is greater than the second element in min.length it is labeled as "recently cultivated/harvested".

Examples

Run this code
# NOT RUN {
{

x <- c(293, 770, 1166, 1166, 1562, 2357, 3234, 
5806, 5806, 5678, 5678, 5546, 5536, 5536, 5536, 
5325, 5200, 4726, 3550, 2868, 2365, 2365, 2365)

n <- countCropCycles(x)

}
# }

Run the code above in your browser using DataLab