Learn R Programming

rgr (version 1.0.4)

ltdl.fix: Replace Negative Values Representing Less Than Detects for a Vector

Description

Function to process a numeric vector to replace negative values representing less than detects (<value) with positive half that value. This permits processing of these effectively categorical data as real numbers and their display on logarithmically scaled axes. In addition, some software packages replace blank fields that should be interpreted as NAs, i.e. no information, with zeros. The facility is provided to replace any zero values with NAs. In other instances data files have been built using an integer code, e.g., -9999, to indicate 'no data', i.e. the equivalent of NAs. The facility is provided to replace any so coded values with NAs. A report of the changes made is displayed on the current device. For processing data matrices or dataframes, see ltdl.fix.df.

Usage

ltdl.fix(x, zero2na = FALSE, coded = NA)

Arguments

x
name of the vector to be processed.
zero2na
to replace any zero values with NAs, set zero2na = TRUE.
coded
to replace any numeric coded values, e.g., -9999 with NAs, set coded = -9999.

Value

  • A numeric vector identical to that input but where any negative values have been replaced by half their positive values, and optionally any zero or numeric coded values have been replaced by NAs.

See Also

ltdl.fix.df

Examples

Run this code
## Replace any missing data coded as -9999 with NAs and any remaining
## negative values representing less than detects with Abs(value)/2
data(fix.test)
x <- fix.test[, 3]
x
x.fixed <- ltdl.fix(x, coded = -9999)
x.fixed

## As above, and replace any zero values with NAs
x.fixed <- ltdl.fix(x, coded = -9999, zero2na = TRUE)
x.fixed

## Make test data kola.o available, setting a -9999, indicating a
## missing pH measurement, to NA
data(kola.o)
attach(kola.o)
pH.fixed <- ltdl.fix(pH, coded = -9999)

## Display relationship between pH in one pH unit intervals and Cu in 
## O-horizon (humus) soil, extending the whiskers to the 2nd and 98th
## percentiles, finally removing the temporary data vector pH.fixed
bwplot(split(Cu,trunc(pH.fixed+0.5)), log=TRUE, wend = 0.02, 
	xlab = "O-horizon soil pH to the nearest pH unit",
	ylab = "Cu (mg/kg) in < 2 mm O-horizon soil")
rm(pH.fixed)

## Or directly
bwplot(split(Cu,trunc(ltdl.fix(pH, coded = -9999)+0.5)), log=TRUE,  
	wend = 0.02, xlab = "O-horizon soil pH to the nearest pH unit",
	ylab = "Cu (mg/kg) in < 2 mm O-horizon soil")

## Detach test data kola.o
detach(kola.o)

Run the code above in your browser using DataLab