censor: Replace erroneous data by NA

Description Usage Arguments Value Examples

View source: R/censor.R

Description

Replace erroneous data by NA

Usage

1
censor(x, ...)

Arguments

x

input data.frame

...

condition(s) that define bad data, which will be replaced by NA. Each condition is treated separately and all variables used in the condition are affected by the NA replacement.

Value

The input data with some elements replaced by NA

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
x <- read.csv(text="
pressure,salinity,sigma theta
       1,      38,         29
       2,      -2,          2
       3,      56,         28
       4,      37,         35",
check.names=FALSE)

# remove negative salinities
censor(x, salinity < 0)
# variable names with special characters (e.g. spaces) need to be quoted
censor(x, `sigma theta` < 10)

# two conditions that affect the same column can be defined at once
censor(x, salinity < 0 | salinity > 40)
# or one after the other
censor(x, salinity < 0, salinity > 40)

# but when several names appear in a single condition,
# all columns are affected.
censor(x, salinity < 0 | `sigma theta` > 32)
# and the result is therefore different from
censor(x, salinity < 0 , `sigma theta` > 32)
# so, to affect column B based on a condition in column A only,
# use a dummy, always TRUE, condition for B, just so that it appears
censor(x, salinity < 0 & `sigma theta` > -Inf)

jiho/castr documentation built on April 5, 2020, 2:12 p.m.