0% found this document useful (0 votes)
29 views2 pages

R Data Types

The document outlines basic data types in R, including numerics, integers, logical values, and characters. It explains how to create and check these data types using examples and the class() function. The document concludes by indicating that the next topic will cover vectors, a key data structure in R.

Uploaded by

Nayana Mathadeen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

R Data Types

The document outlines basic data types in R, including numerics, integers, logical values, and characters. It explains how to create and check these data types using examples and the class() function. The document concludes by indicating that the next topic will cover vectors, a key data structure in R.

Uploaded by

Nayana Mathadeen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

R Data Types

Let's discuss some basic data types in R.

Numerics
Decimal (floating point values) are part of the numeric class in R

In [1]:

n <- 2.2

Integers
Natural (whole) numbers are known as integers and are also part of the numeric class

In [3]:

i <- 5

Logical
Boolean values (True and False) are part of the logical class. In R these are written in All Caps.

In [5]:

t <- TRUE
f <- FALSE

In [6]:

Out[6]:

TRUE

In [7]:

Out[7]:

FALSE

Characters
Text/string values are known as characters in R. You use quotation marks to create a text character string:

In [8]:

char <- "Hello World!"

In [15]:

char

Out[15]:

'Hello World!'

In [16]:

# Also single quotes


c <- 'Single Quote Char'

In [17]:

Out[17]:

'Single Quote Char'


Checking Data Type Classes
You can use the class() function to check the data type of a variable:

In [10]:

class(t)

Out[10]:

'logical'

In [11]:

class(f)

Out[11]:

'logical'

In [18]:

class(char)

Out[18]:

'character'

In [19]:

class(c)

Out[19]:

'character'

In [13]:

class(n)

Out[13]:

'numeric'

In [14]:

class(i)

Out[14]:

'numeric'

Those are some of the basic data types in R. Next we will learn about one of the main data building blocks of R, the vector!

You might also like