char2num: Convert Strings to Numbers

View source: R/functions.R

char2numR Documentation

Convert Strings to Numbers

Description

Convert strings to numbers.

Usage

char2num(s, dec = ",", big.mark = ".")

Arguments

s

a character vector

dec

character: the decimal point; will be replaced with “.

big.mark

character: will be removed, see Details.

Details

char2num uses as.numeric on a character vector after removing/replacing certain characters: all occurences of big.mark are removed, and dec is changed to a dot.

Value

a character vector

Author(s)

Enrico Schumann

See Also

as.numeric, type.convert

Examples

char2num("12.000,23")
char2num("12,000.23", big.mark = ",")
char2num("12000.23",  big.mark = " ") ## but 'as.numeric' is simpler
char2num("12'000.23", big.mark = "'")
char2num("12 000|23", dec = "|", big.mark = " ")

enricoschumann/esutils documentation built on Feb. 2, 2024, 10:03 a.m.