Saurabh Gokhale
Saurabh Gokhale

Reputation: 46425

Integer vs Numeric Datatype in R

This is a question I had while going through R programming course from Coursera. I had asked this question in their forums, but didn't get any answer.

So I thought, I should ask it here.

As I understand what Professor was talking about in that lecture - by default, when we store any number value in variable such as shown below

x <- 1
x

# prints numeric
class(x)

But why is it that when we store a vector such as shown below (note: still without the 'L' symbol to force it as an integer)

x <- 1:10
x

# prints "integer", but why?
class(x)

I thought it should give me a numeric vector, but it is not the case.

Can anybody please explain what is happening here?

Upvotes: 0

Views: 837

Answers (1)

fishtank
fishtank

Reputation: 3728

this has been discussed, see http://r.789695.n4.nabble.com/Integer-vs-numeric-td847329.html From help(":")

Value:

     For numeric arguments, a numeric vector.  This will be of type
     'integer' if 'from' is integer-valued and the result is 
     representable in the R integer type, otherwise of type '"double"'
     (aka 'mode' '"numeric"').

Upvotes: 2

Related Questions