-1
z = 1
typeof(z)
z = 1L
typeof(z)

the above code gives me the output as the double and then folow up by integer but why as we know that 1 is also an integer and to make it integer 'L' is added to the back of it. What is the reason ?

image of the issue in the console

I was checking the data type of the variable, I was expecting both the variable to be integer

jpsmith
  • 11,023
  • 5
  • 15
  • 36
  • `typeof` tells you the underlying storage mode of an object, but this isn't relevant to most end-users. The different representations of numeric types in the underlying C code is abstracted away in most circumstances, and R will happily convert between them without telling you (try `z <- 2L; y <- z/z; typeof(y)`). It would be difficult to find a function outside of `typeof` and `storage.mode` where there is any difference between `1` and `1L`. If for some reason you really want to force a number to be _stored_ as an integer, put an `L` at the end, otherwise it will be stored as a double. – Allan Cameron Aug 05 '23 at 17:46

0 Answers0