0% found this document useful (0 votes)
2 views9 pages

Data Types & Operators

The document provides an overview of data types and operators in R, focusing on common data types such as numeric, integer, logical, character, and complex. It also covers assignment, arithmetic, relational, and logical operators, along with examples for each. Additionally, it lists common functions used in R for statistical analysis, logical operations, rounding, and object inspection.

Uploaded by

mh5675508
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)
2 views9 pages

Data Types & Operators

The document provides an overview of data types and operators in R, focusing on common data types such as numeric, integer, logical, character, and complex. It also covers assignment, arithmetic, relational, and logical operators, along with examples for each. Additionally, it lists common functions used in R for statistical analysis, logical operations, rounding, and object inspection.

Uploaded by

mh5675508
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
You are on page 1/ 9

Applied Statistics for Data

Scientists with R
Class 02: Data Types & Operators

www.aiquest.org Class 02: Data Types & Operators 1


Learning Objective
1. Data types and variables
2. Common operators
3. Common functions

www.aiquest.org Class 02: Data Types & Operators 2


Common Data Types in R

Data type Example typeof() mode()


Numeric 6, 3.14, 10 double numeric
Integer 6L, 3L, 10L integer numeric
Logical TRUE, FALSE logical logical
Character “Female”, “Success”, “a” character character
Complex 4+3i, 2+9i complex complex

www.aiquest.org Class 02: Data Types & Operators 3


Combine Multiple Elements

• When working with multiple elements of a data type, use the function c() to
combine multiple elements.

www.aiquest.org Class 02: Data Types & Operators 4


Assignment operators in R

Operators Example
x <- 10
<-
y <- c(3, 2)
-> 10 -> x
= X = 10
<<- x <<- 10
->> 10 ->> x

www.aiquest.org Class 02: Data Types & Operators 5


Arithmetic operators in R

Operators Description Example


+ Addition / Sum 10+3 = 13
- Subtraction / Minus 10-3 = 7
/ Division 10/3 = 3.333333
* Multiplication 10*3 = 30
^ Exponent / Power 10^3 = 1000
%% Modulus (Remainder from division) 10%%3 = 1
%/% Integer division 10%/%3 = 3
%*% Matrix Multiplication

www.aiquest.org Class 02: Data Types & Operators 6


Relational operators in R

Operators Description Example


4 < 2 FALSE
< Less than 4 < 10 TRUE
4 <=5 FALSE
<= Less than or equal to 4 <= 4 TRUE
> Greater than 4 > 2 TRUE

>= Greater than or equal to 4 >= 2 FALSE

== Equal 3 == 5 FALSE

!= Not equal 3 != 5 TRUE

%in% Included in ‘a’ %in% c(‘b’, ‘a’, ‘c’) TRUE

www.aiquest.org Class 02: Data Types & Operators 7


Logical operators in R

Operators Description Example

& And

| Or

! Not

Note: Relational operators compare values and return either TRUE or FALSE. Logical operators perform logical
operations on TRUE and FALSE.

www.aiquest.org Class 02: Data Types & Operators 8


Common functions in R

Group Functions
sum(), mean(), min(), max(), median(),
Statistical
quantile(), sd(), range(), summary()

Logical is.na(), any(), all(), which()


Rounding round(), floor(), ceiling()
Other mathematical sqrt(), abs(), log(), exp()
Vector operation length(), seq(), rep(), unique()
Object inspection str(), typeof(), mode()
Utility help(), install.packages(), library()

www.aiquest.org Class 02: Data Types & Operators 9

You might also like