as_irgenwas: as_numeric and as_logical

as_irgenwasR Documentation

as_numeric and as_logical

Description

as_numeric: character, factor to numeric

as_numeric: beim Type character wird die Funktion readr::parse_number ausgeführt. parse_number(x, na = c(".", ","), trim_ws=TRUE)

as_numeric: beim Type factor wird zu erst versucht aus den labels die Zahlen zu extrahieren und erst wenn das nicht geht die levels (1:n).

as_numeric: beim Type factor wird zu erst versucht aus den labels die Zahlen zu extrahieren und erst wenn das nicht geht die levels (1:n).

as_logical: alles mit zwei Merkmalen zu logical

Usage

as_numeric(x, ...)

## S3 method for class 'numeric'
as_numeric(x, ...)

## S3 method for class 'character'
as_numeric(x, na.string = "", dec = c(".", ","), trim_ws = TRUE, ...)

## S3 method for class 'factor'
as_numeric(x, na.string = "", dec = c(".", ","), ...)

## S3 method for class 'logical'
as_numeric(x, ...)

as_logical(x)

Arguments

x

vector

...

readr::parse_number trim_ws Should leading and trailing whitespace (ASCII spaces and tabs) be trimmed from each field before parsing it?

na.string

missing

dec

decimal

trim_ws

logical trim ws

Value

vector

Examples


dummy <- factor(c("3", "4", "6"))
as_numeric(dummy)

 x <-
c(
  "> 15100",
  "+1",
  "-1",
  "655.39554148943",
  "699.913201822519 ",
  " 228.40319734460499",
  "",
  NA,
  "hallo1",
  "-77"
)
as_numeric(x,  na.string = c("", "-77"))

stp4/stp25tools documentation built on Feb. 27, 2025, 11:14 p.m.