transformQuantitativeScale: Transform quantitative scale

View source: R/transformQuantitativeScale.R

transformQuantitativeScaleR Documentation

Transform quantitative scale

Description

Transforms all the values in a VegX object made using a quantitative scale into another quantitative scale following a given transformation function.

Usage

transformQuantitativeScale(
  target,
  method,
  newMethod,
  FUN,
  replaceValues = FALSE,
  verbose = TRUE
)

Arguments

target

The initial object of class VegX to be modified.

method

An integer (index) or a name of the original quantitative scale method.

newMethod

An integer (index) or a name of a quantitative method existing in the initial object, or an object of class VegXMethodDefinition.

FUN

A function used to transform numeric values.

replaceValues

A boolean flag to indicate that values in the new scale should replace the old ones, instead of defining new measurements. For some measurements transformations will not be possible if replacement is not forced using this flag.

verbose

A boolean flag to indicate console output of the data transformation process.

Details

The function will normally create new measurements without destroying the original ones, unless replacement is forced by setting replaceValues = TRUE. Veg-X only allows a single measurement per observations of some kinds:

  • "diameterMeasurement" and "heightMeasurement" of indvidual organism observations.

  • "heightMeasurement" of aggregate organism observations.

  • "lowerLimitMeasurement" and "upperLimitMeasurement" of stratum observations.

In these cases, scale transformations are not possible if replaceValues = FALSE.

Value

The modified object of class VegX.

See Also

Other transform functions: transformOrdinalScale()

Examples

data(mokihinui)

# Create initial Veg-X document with stratum heights in meters
mapping = list(plotName = "Plot", obsStartDate = "PlotObsStartDate", 
               stratumName = "Tier",
               lowerLimitMeasurement = "TierLower", 
               upperLimitMeasurement = "TierUpper")
heightMethod1 = predefinedMeasurementMethod("Stratum height/m")
strataDef = defineMixedStrata(name = "Recce strata",
               description = "Standard Recce stratum definition",
               citation = "Hurst, JM and Allen, RB. (2007) 
                   The Recce method for describing New Zealand vegetation – 
                   Field protocols. Landcare Research, Lincoln.",
               heightStrataBreaks = c(0, 0.3,2.0,5, 12, 25, 50),
               heightStrataNames = paste0("Tier ",1:6),
               categoryStrataNames = "Tier 7",
               categoryStrataDefinition = "Epiphytes")
x = addStratumObservations(newVegX(), moki_str,
               mapping = mapping,
               methods = list(lowerLimitMeasurement = heightMethod1,
                              upperLimitMeasurement = heightMethod1),
               stratumDefinition = strataDef)

# Examine stratum heights
showElementTable(x, "stratumObservation")

# Transform stratum heights from m to cm by multiplying values by 10
# ('replaceValues' needs to be set to TRUE to force replacement)
heightMethod2 = predefinedMeasurementMethod("Stratum height/cm")
y = transformQuantitativeScale(x, "Stratum height/m", heightMethod2,
                               function(x){return(x*10)}, 
                               replaceValues = TRUE)
# Examine new stratum heights
showElementTable(y, "stratumObservation")


miquelcaceres/VegX documentation built on Sept. 18, 2022, 7:04 p.m.