On Wed, 14 Jan 2004 [EMAIL PROTECTED] wrote:

> I am trying to figure out R data types and/or storage mode.  For example:

[...]

> So it looks like R stores numbers as doubles unless the are converted to
> integers (long) with the as.integer() function or they are created with the
> : operator.  If any of the numbers to a function are not type integer than
> the function returns type double.  Is this the case?  Thanks.

Nearly!

Non-complex `numbers' can have storage mode "double" or "integer".  
Storage mode "integer" is the C `int' type and not the C `long' type, so
probably on all current R platforms doubles are stored in 8 bytes and
integers in 4.

The storage mode is largely under the user/programmer's control: you can 
do

storage.mode(x) <- "double"

for example.  The storage mode of the return value of a function depends 
on how it was programmed, not on the types of its arguments, for example

> x <- seq(10)
> storage.mode(x)
[1] "integer"

Just a few base functions normally return integer results: you have 
mentioned : and as.integer() and I have illustrated seq().  table() and 
tabulate() are two others I know of, and factors are integer vectors with 
particular attributes.

Current versions of S use integer storage mode much more widely, and it is 
quite possible that in due course more functions in R will make use of it.

-- 
Brian D. Ripley,                  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to