Learn R Programming

fritools (version 4.6.0)

str2num: Convert Character Numbers to Numeric

Description

If you read text containing (possibly German, i.e. the decimals separated by comma and dots inserted for what they think of as readability) numbers, you may want to convert them to numeric.

Usage

str2num(x)

Value

The number as a numeric.

Arguments

x

A string representing a (possibly German) number.

See Also

Other bits and pieces: golden_ratio(), is_difftime_less(), is_valid_primary_key(), pause(), r_cmd_install(), rownames2col(), string2words(), strip_off_attributes(), tapply(), throw()

Examples

Run this code
line_in_text <- "foo bar 10.303,70 foo bar  1.211.000,55 foo bar"
words <- unlist(strsplit(line_in_text, split = " "))
print(na.omit(sapply(words, str2num)), digits = 9)
print(str2num(words[c(3, 4, 7)]), digits = 9)
print(str2num(words[7]), digits = 9)

Run the code above in your browser using DataLab