Лабораторное занятие № 2. Презентация

Содержание

Слайд 2

Vasily V. Grinev. Introduction to R Programming

LIST OF PRACTICAL TASKS

Task by task.
Task

Vasily V. Grinev. Introduction to R Programming LIST OF PRACTICAL TASKS Task
#6: Development a multi-component R command.
Task #7: Handling with character constants.
Task #8: Handling with numeric constants.
Task #9: Handling with built-in constants.
Task #10: Using operators.
Task #11: Using built-in functions.
Duration.
Eighty minutes (in total) per group of students.

Слайд 3

Components of R commands:
constants;
variabilities;
operators;
functions;
control structures.

PRACTICAL TASK #6: Development a multi-component R command

When completing

Components of R commands: constants; variabilities; operators; functions; control structures. PRACTICAL TASK
the first task, you must create a multi-component R command that would include constant(-s), variability(-ies), operator(-s) and function(-s).

Vasily V. Grinev. Introduction to R Programming

See videolecture “Videolecture #2.1. How R works” at YouTube hosted Grinev's Educational Channel
https://www.youtube.com/watch?v=4bsf23GKy8c
for future details.

> paste("A circle with a diameter of", 5, "cm", "has circumference",
+ round(pi * 5, digits=3), "cm")

Слайд 4

Vasily V. Grinev. Introduction to R Programming

A constant is entity whose value(-s)

Vasily V. Grinev. Introduction to R Programming A constant is entity whose
cannot be altered.
A variable is an object used to store data whose value(-s) can be changed if necessary.
There are built-in and user-defined constants. Basic classes of constants are character constants and numeric constants.
Character constants can be represented using either single quotes (') or double quotes (") as delimiters.
> "example"
[1] "example"
> typeof(x="example")
[1] "character"

Basic definitions

PRACTICAL TASK #7: Handling with character constants

Слайд 5

Vasily V. Grinev. Introduction to R Programming

Creating a character constant:

Task content

PRACTICAL TASK

Vasily V. Grinev. Introduction to R Programming Creating a character constant: Task
#7: Handling with character constants

> "example"
[1] "example“
> con <- "example"
> con
[1] "example"

Replacement of constant:

> con1 <- "blood"
> con1
[1] "blood"
> con2 <- sub(pattern="loo", replacement="rea", x=con1)
> con2
[1] "bread"

Слайд 6

Vasily V. Grinev. Introduction to R Programming

Concatenation of character strings:

Task content

PRACTICAL TASK

Vasily V. Grinev. Introduction to R Programming Concatenation of character strings: Task
#7: Handling with character constants

> con1 <- "I"
> con2 <- "love"
> con3 <- "R"
> con <- paste(con1, con2, con3, sep=" ")
> con
[1] "I love R"
> con <- paste("I", "love", "R", sep=" ")
> con
[1] "I love R"

Splitting of character string:

> con <- paste("I", "love", "R", sep=" ")
> con
[1] "I love R"
> strsplit(x=con, split=" ")[[1]]
[1] "I" "love" "R"

Слайд 7

Vasily V. Grinev. Introduction to R Programming

Numeric constants belong to three types:
integer

Vasily V. Grinev. Introduction to R Programming Numeric constants belong to three
(integer numbers)
> 4L
[1] 4
> typeof(x=4L)
[1] "integer"
double (double precision floating point numbers)
> 4.5
[1] 4.5
> typeof(x=4.5)
[1] "double"
complex (complex numbers)
> 4.5i
[1] 0+4.5i
> typeof(x=4i)
[1] "complex"

PRACTICAL TASK #8: Handling with numeric constants

Basic definitions

Слайд 8

Vasily V. Grinev. Introduction to R Programming

Creating an integer constant:

Task content

### by

Vasily V. Grinev. Introduction to R Programming Creating an integer constant: Task
appending an L suffix
> con <- 5L
> con
[1] 5
### by function as.integer()
> con <- as.integer(x=5)
> con
[1] 5
> as.integer(x=5.4)
[1] 5
> as.integer(x="5.4")
[1] 5
> as.integer(x="love")
[1] NA
Warning message:
NAs introduced by coercion

PRACTICAL TASK #8: Handling with numeric constants

Слайд 9

Vasily V. Grinev. Introduction to R Programming

Inspection a type and/or class of

Vasily V. Grinev. Introduction to R Programming Inspection a type and/or class
integer constant:

Task content

> con <- 5L
### by function typeof()
> typeof(x=con)
[1] "integer"
### by function class()
> class(x=con)
[1] "integer“
### by function is.integer()
> is.integer(x=con)
[1] TRUE

PRACTICAL TASK #8: Handling with numeric constants

Слайд 10

Vasily V. Grinev. Introduction to R Programming

The reasons for existing integer constants:
The

Vasily V. Grinev. Introduction to R Programming The reasons for existing integer
integer is represented explicitly. At the same time, the representing real numbers always involves an approximation and a potential loss of significant digits.
Testing for the equality of two real numbers is not a realistic way to think when dealing with the numbers in a computer. Direct comparison of real numbers can cause errors.
Performing arithmetic on very small or very large real numbers can lead to errors that are not possible in abstract mathematics.
The more bits we use to represent a real number, the greater the precision of the representation and the more memory we consume.
### memory allocation
> object.size(x=1:100)
448 bytes
> object.size(x=as.numeric(x=1:100))
848 bytes

Task content

PRACTICAL TASK #8: Handling with numeric constants

Слайд 11

Vasily V. Grinev. Introduction to R Programming

There are several built-in constants:
The 26

Vasily V. Grinev. Introduction to R Programming There are several built-in constants:
upper-case letters of the Roman alphabet
> LETTERS
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q"
[18] "R" "S" "T" "U" "V" "W" "X" "Y" "Z"
The 26 lower-case letters of the Roman alphabet
> letters
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t"
[21] "u" "v" "w" "x" "y" "z"
The English names for the months of the year
> month.name
[1] "January" "February" "March" "April" "May" "June" "July" "August"
[9] "September" "October" "November" "December"
The three-letter abbreviations for the English month names
> month.abb
[1] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct"
[11] "Nov" "Dec"
The ratio of the circumference of a circle to its diameter
> pi
[1] 3.141593

PRACTICAL TASK #9: Handling with built-in constants

Basic definitions

Слайд 12

Vasily V. Grinev. Introduction to R Programming

Some manipulations with character built-in constants:

Task

Vasily V. Grinev. Introduction to R Programming Some manipulations with character built-in
content

> LETTERS
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T"
[20] "T" "U" "V" "W" "X" "Y" "Z"
> tolower(x=LETTERS)
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v“
[23] "w" "x" "y" "z"
> toupper(x=letters)
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T"
[20] "T" "U" "V" "W" "X" "Y" "Z"

PRACTICAL TASK #9: Handling with built-in constants

> month.name
[1] "January" "February" "March" "April" "May" "June" "July" "August"
[9] "September" "October" "November" "December“
> substr(x=month.name, start=1, stop=3)
[1] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"

Слайд 13

Vasily V. Grinev. Introduction to R Programming

There are several special built-in constants:
Infinity
>

Vasily V. Grinev. Introduction to R Programming There are several special built-in
Inf
[1] Inf
Not Available; it is used to indicate missing values in the data
> NA
[1] NA
Not A Number; it indicates an undefined number or "not a number"
> NaN
[1] NaN
A null object; it is often used when the return value of an expression or function is not defined
> NULL
NULL

PRACTICAL TASK #9: Handling with built-in constants

Basic definitions

Слайд 14

Vasily V. Grinev. Introduction to R Programming

Some manipulations with special built-in constants:

Task

Vasily V. Grinev. Introduction to R Programming Some manipulations with special built-in
content

> v <- 4:13
> v
[1] 4 5 6 7 8 9 10 11 12 13
> v[c(2, 4, 7)] <- c(5/0, NA, NaN)
> v
[1] 4 Inf 6 NA 8 9 NaN 11 12 13

PRACTICAL TASK #9: Handling with built-in constants

> is.na(x=v)
[1] FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE
> is.nan(x=v)
[1] FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE
> is.finite(x=v)
[1] TRUE FALSE TRUE FALSE TRUE TRUE FALSE TRUE TRUE TRUE
> is.infinite(x=v)
[1] FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
> table(is.infinite(v))
FALSE TRUE
9 1

Слайд 15

In any programming language, an operator is a symbol that tells the

In any programming language, an operator is a symbol that tells the
compiler or interpreter to perform specific operation and produce final result.
Type (category) of operators in R:
arithmetic operators;
relational operators;
logical operators;
assignment operators;
miscellaneous operators.
You can get help about any operator via ?"operator_name".

Vasily V. Grinev. Introduction to R Programming

For future reading:
1) Operator (computer programming) (https://en.wikipedia.org/wiki/Operator_(computer_programming))
2) Basics of operators (https://www.hackerearth.com/ru/practice/basic-programming/operators)
3) R operators (https://www.datamentor.io/r-programming/operator)
4) R-operators (https://www.tutorialspoint.com/r/r_operators.htm)
5) Operators in C/C++ (https://www.geeksforgeeks.org/operators-c-c/)
6) Java - Basic operators (https://www.tutorialspoint.com/java/java_basic_operators.htm)

PRACTICAL TASK #10: Using operators

Basic definitions

Слайд 16

R arithmetic operators

Vasily V. Grinev. Introduction to R Programming

These operators perform standard

R arithmetic operators Vasily V. Grinev. Introduction to R Programming These operators
arithmetic operations with each element of the vector.

PRACTICAL TASK #10: Using operators

Слайд 17

R relational operators

Vasily V. Grinev. Introduction to R Programming

Each element of the

R relational operators Vasily V. Grinev. Introduction to R Programming Each element
first vector is compared with the corresponding element of the second vector. The result of comparison is a Boolean value.

PRACTICAL TASK #10: Using operators

Слайд 18

R logical operators

Vasily V. Grinev. Introduction to R Programming

It is applicable to

R logical operators Vasily V. Grinev. Introduction to R Programming It is
logical, numeric or complex vectors. Each element of the first vector is compared with the corresponding element of the second vector. The result of comparison is a Boolean value. The logical operator && and || considers the first element of the vectors and give a single element output.

PRACTICAL TASK #10: Using operators

Слайд 19

R assignment operators

Vasily V. Grinev. Introduction to R Programming

These operators are used

R assignment operators Vasily V. Grinev. Introduction to R Programming These operators
to assign values to variables. The operators <- and = can be used to assign to variable in the same environment. The <<- operator is used for assigning to variables in the parent environments.

PRACTICAL TASK #10: Using operators

Слайд 20

R miscellaneous operators

Vasily V. Grinev. Introduction to R Programming

These operators are used

R miscellaneous operators Vasily V. Grinev. Introduction to R Programming These operators
for specific purposes and not general arithmetic or logical computation.

PRACTICAL TASK #10: Using operators

Слайд 21

R miscellaneous operators

Vasily V. Grinev. Introduction to R Programming

PRACTICAL TASK #10: Using

R miscellaneous operators Vasily V. Grinev. Introduction to R Programming PRACTICAL TASK #10: Using operators
operators

Слайд 22

Vasily V. Grinev. Introduction to R Programming

Practice with all main R operators.

Vasily V. Grinev. Introduction to R Programming Practice with all main R
Use the true data sets.

Task content

> v <- 4:13
> v
[1] 4 5 6 7 8 9 10 11 12 13
> v + 1
[1] 5 6 7 8 9 10 11 12 13 14

PRACTICAL TASK #10: Using operators

Слайд 23

Built-in function is a function which already created or defined in the

Built-in function is a function which already created or defined in the
programming framework.
Built-in functions in R:
math, or numeric, functions;
character, or string, functions;
basic statistical functions;
statistical probability functions;
other functions.
You can get help about any built-in function via ?function_name.

Vasily V. Grinev. Introduction to R Programming

See videolecture “Videolecture #9.1. Introduction in R functions” at YouTube hosted Grinev's Educational Channel https://www.youtube.com/watch?v=Lf-B4fNXm1g&t=696s
for future details.

PRACTICAL TASK #11: Using built-in functions

Basic definitions

Слайд 24

R math functions

Vasily V. Grinev. Introduction to R Programming

PRACTICAL TASK #11: Using

R math functions Vasily V. Grinev. Introduction to R Programming PRACTICAL TASK #11: Using built-in functions
built-in functions

Слайд 25

R character functions

Vasily V. Grinev. Introduction to R Programming

PRACTICAL TASK #11: Using

R character functions Vasily V. Grinev. Introduction to R Programming PRACTICAL TASK #11: Using built-in functions
built-in functions

Слайд 26

R basic statistical functions

Vasily V. Grinev. Introduction to R Programming

PRACTICAL TASK #11:

R basic statistical functions Vasily V. Grinev. Introduction to R Programming PRACTICAL
Using built-in functions

Слайд 27

Vasily V. Grinev. Introduction to R Programming

Practice with all main R built-in

Vasily V. Grinev. Introduction to R Programming Practice with all main R
functions. Use the true data sets.

Task content

> v <- 4:13
> v
[1] 4 5 6 7 8 9 10 11 12 13
> sqrt(x=v)
[1] 2.00000 2.23607 2.44949 2.64575 2.82843 3.00000 3.16228 3.31662
[9] 3.46410 3.60555

PRACTICAL TASK #11: Using built-in functions

Имя файла: Лабораторное-занятие-№-2.-Презентация.pptx
Количество просмотров: 22
Количество скачиваний: 0