Search notes:

R function: as.integer

Converting a numerical (double) into an integer

Number literals that look like integers (for example 4) are internally stored as doubles. as.integer() converts them to integers.
If a number literal is suffixed with an L, its type is integer:
four <- 4;
typeof(four);
#
#  "double"

four_int <- as.integer(four);
typeof(four_int);
#
#  "integer"

five <- 5L;
typeof(five);
#
#   "integer"
Github repository about-r, path: /functions/as/integer/double.R

Applying as.integer on a factor

Factors are internally stored as a vector of integers. Applying as.integer(…) on a factor displays these integers:
fac <- factor(c('foo', 'bar', 'foo', 'baz', 'bar'));
levels(fac);
#
#  "bar" "baz" "foo"

as.integer(fac);
#
#  3 1 3 2 1
Github repository about-r, path: /functions/as/integer/factor.R

Applying as.integer on a POSIXct object

If as.integer() is applied on a POSIXct object, it returns the number of seconds since 1970-01-01:
as.integer(ISOdate(1970, 1, 1, 0, 0, 0))
# [1] 0

as.integer(ISOdate(1970, 1, 1, 0, 0, 1))
# [1] 1

as.integer(ISOdate(1970, 1, 1, 0, 1, 0))
# [1] 60

as.integer(ISOdate(1971, 1, 1, 0, 0, 0)) / 24 / 60 / 60
# [1] 365
Github repository about-r, path: /functions/as/integer/POSIXct.R

See also

Index to (some) R functions

Index