Book Image

Mastering Scientific Computing with R

Book Image

Mastering Scientific Computing with R

Overview of this book

Table of Contents (17 chapters)
Mastering Scientific Computing with R
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Floating point operations and numerical data types


From the standpoint of mathematical operations, we usually think of numbers as just that. However, a computer takes a more broken down approach to numbers. Most of the time this doesn't matter, but when we have to deal with large datasets and are concerned about either memory or speed, it can make a big difference. R essentially has two numeric data types; integer and double precision (also called numeric). The integer data type handles exact values denoted as integers. As per the IEEE floating point standard, the double precision type handles values as rounded decimals. R has no single data type as is used in languages like C.

Here, we will create two vectors of integers, x and y, and divide one by the other. Mathematically (but not computationally), we get whole number results. Let's look at the following code:

> x <- as.integer(seq(1, 10, by = 1))
> y <- as.integer(seq(2, 20, by = 2))
> x
 [1]  1  2  3  4  5  6  7  8  9 10...