Integers
We have discussed the numeric class. We just saw that the seq
function can generate objects of this class. For another example, type
class(seq(1, 10, 0.5))
into the console and note that the class
is numeric. R has another type of vector we have not described, the integer class. You can create an integer by adding the letter L
after a whole number. If you type
class(3L)
in the console, you see this is an integer and not a numeric. For most practical purposes, integers and numerics are indistinguishable. For example 3, the integer, minus 3 the numeric is 0. To see this type this in the console
3L - 3
The main difference is that integers occupy less space in the computer memory, so for big computations using integers can have a substantial impact.
This exercise is part of the course
Data Science R Basics
Exercise instructions
Does this change depending on what we store in an object?
What is the class of the following object a <- seq(1, 10)
?
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Store the sequence in the object a
# Determine the class of a