Types and coercion in R
R's atomic types and the rules that convert between them.
count <- 42L
ratio <- 3.14
label <- "typestar"
flag <- TRUE
missing <- NA
is_int <- is.integer(count)
as_double <- as.numeric(count)
as_text <- as.character(ratio)
kind <- class(label)
mixed <- c(1, "two", TRUE)
coerced <- class(mixed)
How it works
42Lis integer; plain3.14is double.as.numericandas.characterconvert explicitly.- Mixing types in
c()silently coerces to the widest one.
Keywords and builtins used here
cclass
The run, in numbers
- Lines
- 13
- Characters to type
- 237
- Tokens
- 57
- Three-star pace
- 80 tpm
At the three-star pace of 80 tokens a minute, this run takes about 43 seconds.
Step 2 of 4 in Vectors & types, step 2 of 20 in Language basics.