I am having trouble understanding how classes in R work. Here is a small
reproducable example:
> x=1
> class(x)
[1] "numeric"
OK. When a variable is a number, its class is "numeric". Does R have
multiple types for numbers, like C++ (eg integer, float, double). If so,
where can I see a list, and how does "numeric" fit into this system?
> x=1:100
> class(x)
[1] "integer"
Wait - I thought that I assigned x to be an array/vector of 100 integers
(numerics). Why is the class not "array" or "vector". How is "integer"
different than "numeric"? Is there a "vector" or "array" class in R? If
so, why is this not that?
> class(x[1])
[1] "integer"
This is even more confusing to me. Because x[1] is 1. And the class of
that was "numeric" in my first example. Why is it integer now?
> x=1.5:100.5
> class(x)
[1] "numeric"
Why is this class "numeric" when the class of 1:100 was integer?
Thanks for your help.
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.