chr_numeric: Charcter to numeric conversion

Description Usage Arguments Examples

Description

Convert a character to a numeric expression.

Usage

1
2
chr_numeric(column, validate_min = NA, validate_max = NA, digits = NA,
  decimals = "point", na_id = "NA", is_integer = FALSE)

Arguments

column

A column from a survey data frame where gender is recorded.

validate_min

The valid minimum value. Defaults to NA in which case no validation takes place.

validate_max

The valid maximum value. Defaults to NA in which case no validation takes place.

digits

How many digits are valid in the raw date. Defaults to NA when digits are not truncated. 2 uses only the first two characters of the raw data. Digits are counted as characters. So keeping 1.5 requires digit = 3.

decimals

Defaults to "point", alternative is "comma"

na_id

Is there a special character ID for missing variables? (Default: "NA" )

is_integer

Numeric or integer should be returned? Defaults to FALSE in which case no validation takes place. If you get a warning with NA conversion, you are likely to have several NA characters, such as missing and NA at the same time.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
chr_numeric(column = as.character (c(1982, 1990.5, 2019,
                                     "missing", NA, 1678)),
            validate_min  = 1900, validate_max = 2017,
            digits = NA, decimals = "point",
            na_id = "missing",
            is_integer = FALSE )
chr_numeric(column = as.character (c("1 - egyet", "11 - tizenegyet",
            "missing", "2")),
            validate_min  = NA, validate_max = NA,
            digits = 2,
            na_id = "missing",
            is_integer = FALSE )

antaldaniel/surveyreader documentation built on May 16, 2019, 2:29 a.m.