as.numeric2: An Enhanced Version of as.numeric

Description Usage Arguments Value Examples

View source: R/as.numeric2.R

Description

This function coerces objects into a numeric vector. There are several differences between this function and as.numeric. First, if as.character2 fails to coerce (this is usually because there are characters in the input object), it will raise an error and stop rather than to give a warning. Second, it can handle data frame object, list, and recursive list. Third, it can coerce number-like factors exactly into what users see on the screen.

Usage

1

Arguments

...

one or more objects to be coerced.

Value

a numeric vector, or, if fails, an error will be raised.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Try to coerce data frame
a <- c(55, 66, 77, 88, 66, 77, 88)
b <- factor(a)
df <- data.frame(a, b)
as.numeric2(df, a*2)
# Try a list
l <- list(a, a*2)
as.numeric2(l)
# Try a list of lists
l2 <- list(l, l)
as.numeric2(l2)

chinese.misc documentation built on Sept. 13, 2020, 5:13 p.m.