Integer
In order to create an integer variable in R, we invoke the as.integer function. We can be assured that y is indeed an integer by applying the is.integer function.
> y = as.integer(3)
> y # print the value of y
[1] 3
> class(y) # print the class name of y
[1] "integer"
> is.integer(y) # is y an integer?
[1] TRUE
> y # print the value of y
[1] 3
> class(y) # print the class name of y
[1] "integer"
> is.integer(y) # is y an integer?
[1] TRUE
Incidentally, we can coerce a numeric value into an integer with the same as.integer function.
And we can parse a string for decimal values in much the same way.
On the other hand, it is erroneous trying to parse a non-decimal string.
> as.integer("Joe") # coerce an non−decimal string
[1] NA
Warning message:
NAs introduced by coercion
[1] NA
Warning message:
NAs introduced by coercion
Often, it is useful to perform arithmetic on logical values. Like the C language, TRUE has the value 1, while FALSE has value 0.