I want to preface this by saying I'm an absolute programming beginner, so please excuse how basic this question is.
I'm trying to get a better understanding of "atomic" classes in R and maybe this goes for classes in programming in general. I understand the difference between a character, logical, and complex data classes, but I'm struggling to find the fundamental difference between a numeric class and an integer class.
Let's say I have a simple vector x <- c(4, 5, 6, 6)
of integers, it would make sense for this to be an integer class. But when I do class(x)
I get [1] "numeric"
. Then if I convert this vector to an integer class x <- as.integer(x)
. It return the same exact list of numbers except the class is different.
My question is why is this the case, and why the default class for a set of integers is a numeric class, and what are the advantages and or disadvantages of having an integer set as numeric instead of integer.
as.integer(c(4.1, 5.2, 6.3, 6.4))
help you understanding the difference? You need to understand that the internal representation and what is printed are not the same at all. Anyway, do some reading about data types in computer languages. – Focalx <- 1; is.integer(x); is.numeric(x)
, thenx <- 1L; is.integer(x); is.numeric(x)
and you may be able to see a little of the difference. Integer classes are used more to pass variables from C constructs and also in R structures. Though, there's a lot more to this. – Madrigalist