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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1745475545, '18.222.251.131', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/functions/as/integer/index(88): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78