SlideShare a Scribd company logo
DATA FILES, BLOCKS OF
EXPRESSIONS, CYCLES AND
FUNCTIONS IN R
Vladimir Bakhrushin,
Professor, D.Sc. (Phys. & Math.)
Vladimir.Bakhrushin@gmail.com
Data reading
> data<-read.table(“File name", sep=";", dec=",",
header=TRUE, …)
 first argument is a reference to the file of *.csv format, that
contains data;
 argument sep indicates, by which sign the data are separated;
 argument dec indicates decimal separator for numbers;
 argument header indicates whether the first cells of each
column are the column names;
 argument row.names indicates whether one of columns
contains the row names;
 argument nrows specifies the number of lines that need to be
read from the table.
Data reading
Writing data to a file
write.table(x, file = "", append = FALSE, quote = TRUE, sep = "
", na = "NA", dec = ".", row.names = TRUE, col.names = TRUE,
qmethod = c("escape", "double"), …)
 x – object that must be written to the file (usually it is a matrix
or data table);
 file – name of the file to which the data must be written or
other connections opened to writing;
 append – argument that indicates the need to append data to
an existing file or to create a new file with the same name;
 quote – indicates the need to take in quotes marks of rows
and columns;
 na – character set used for the missing values.
Writing data to a file
write.table(a2, file = "a2.csv", sep =
" ", dec = ".")
Lists
For saving of heterogeneous data in the one object lists can be
used. For example:
> x1 = c("Milk", "Yogurt", "Sour cream", "Curd")
> x2 = c(1, 1, 14, 7)
> x3 = c(TRUE, FALSE)
> l1 = list(Text = x1, Number = x2, Logic = x3)
> l1
To identify specific elements of the list such constructions can be
used :
 l1$Text[3]; l1$Text;
 l1[[1]][2]; l1[[2]].
Lists
Data frames
Data editing using function fix()
Comments, blocks of expressions
Any comment begins with the character #. The test located in
the line after this character not regarded as part of the program
to be executed.
Expressions can be combined into blocks with curly braces.
The result of the expressions block is the result of the last of
them.
> {
+ x = 9;
+ y = 4;
+ x + y;
+ }
[1] 13
Conditional constructs
“If” – “else” statement is an example of conditional construct:
if (<condition>)
{<expression_1>
}else{
<expression_2>}
Loops
Loops with predetermined number of iterations can be
organized using function “for”:
for (<variable> in <expression_1>)
<expression_2>
If it is need to repeat iterations until a certain condition is
fulfilled, we can use a loop “while”:
while (<condition>) {
<expression>
}
Loops
Loops
Infinite loops “Repeat” are
used when a procedure
should be executed if the
interruption condition is not
performed. Command
“break” is used to interrupt
the cycle, and command
“next” – to interrupt the
current iteration and move to
the next one.
Functions
Function in R is an object, that for a given set of arguments
returns a certain value. Usually when the function is declared its
value is assigned to some variable.
<variabe> = function(<arguments>)
{
<expression>
}.
Subsequently, the function can be called using the
construction:
<result> = <variable>(<arguments>).
Functions
Functions
Literature
1. An Introduction to R
2. Introduction to the R Language: Functions
3. R Tutorial: An R introduction to statistics
4. Kelly Black. R Tutorial

More Related Content

What's hot (20)

PDF
2 data types and operators in r
Dr Nisha Arora
 
PPTX
R교육1
Kangwook Lee
 
PDF
C structure and union
Thesis Scientist Private Limited
 
PDF
Postgresql 9.3 overview
Aveic
 
PDF
6. R data structures
ExternalEvents
 
PDF
Java chapter 6 - Arrays -syntax and use
Mukesh Tekwani
 
PDF
Export Data using R Studio
Rupak Roy
 
PDF
Reading Data into R
Kazuki Yoshida
 
PPT
Arrays in c
vampugani
 
PPTX
DDL DATA DEFINATION LANGUAGE
Abrar ali
 
PDF
Import Data using R
Rupak Roy
 
PPTX
MarcEdit Shelter-In-Place Webinar 7: Making Regular Expressions work for you ...
Terry Reese
 
PPTX
Introduction to Data Structure : Pointer
S P Sajjan
 
PDF
2 data structure in R
naroranisha
 
PPTX
Presentation on c programing satcture
topu93
 
PPT
C1320prespost
FALLEE31188
 
PPTX
Sql fundamentals
Ravinder Kamboj
 
PPTX
Array in c++
Mahesha Mano
 
DOC
SQL
Tuhin_Das
 
PPT
SQL : introduction
Shakila Mahjabin
 
2 data types and operators in r
Dr Nisha Arora
 
R교육1
Kangwook Lee
 
C structure and union
Thesis Scientist Private Limited
 
Postgresql 9.3 overview
Aveic
 
6. R data structures
ExternalEvents
 
Java chapter 6 - Arrays -syntax and use
Mukesh Tekwani
 
Export Data using R Studio
Rupak Roy
 
Reading Data into R
Kazuki Yoshida
 
Arrays in c
vampugani
 
DDL DATA DEFINATION LANGUAGE
Abrar ali
 
Import Data using R
Rupak Roy
 
MarcEdit Shelter-In-Place Webinar 7: Making Regular Expressions work for you ...
Terry Reese
 
Introduction to Data Structure : Pointer
S P Sajjan
 
2 data structure in R
naroranisha
 
Presentation on c programing satcture
topu93
 
C1320prespost
FALLEE31188
 
Sql fundamentals
Ravinder Kamboj
 
Array in c++
Mahesha Mano
 
SQL : introduction
Shakila Mahjabin
 

Similar to Files,blocks and functions in R (20)

PPT
Loops and functions in r
manikanta361
 
PPTX
Unit I - 1R introduction to R program.pptx
SreeLaya9
 
PPTX
R programming
Pramodkumar Jha
 
PPTX
DataStructures.pptx
Thanuj Pothula
 
PPTX
R language introduction
Shashwat Shriparv
 
PPTX
data frames.pptx
RacksaviR
 
PPTX
Introduction To Programming In R for data analyst
ssuser26ff68
 
PPTX
Introduction to R for beginners
Abishek Purushothaman
 
PDF
Learning notes of r for python programmer (Temp1)
Chia-Chi Chang
 
PPTX
Programming in R
Smruti Sarangi
 
PPTX
Get started with R lang
senthil0809
 
PDF
[1062BPY12001] Data analysis with R / week 2
Kevin Chun-Hsien Hsu
 
PPTX
世预赛买球-世预赛买球比赛投注-世预赛买球比赛投注官网|【​网址​🎉ac10.net🎉​】
bljeremy734
 
PPTX
世预赛买球-世预赛买球竞彩平台-世预赛买球竞猜平台|【​网址​🎉ac123.net🎉​】
hanniaarias53
 
PPTX
美洲杯买球-美洲杯买球怎么押注-美洲杯买球押注怎么玩|【​网址​🎉ac99.net🎉​】
kokoparmod677
 
PPTX
欧洲杯体彩-欧洲杯体彩比赛投注-欧洲杯体彩比赛投注官网|【​网址​🎉ac99.net🎉​】
lopezkatherina914
 
PPTX
世预赛投注-世预赛投注投注官网app-世预赛投注官网app下载|【​网址​🎉ac123.net🎉​】
bljeremy734
 
PPTX
欧洲杯足彩-欧洲杯足彩线上体育买球-欧洲杯足彩买球推荐网站|【​网址​🎉ac55.net🎉​】
brunasordi905
 
PPTX
欧洲杯下注-欧洲杯下注买球网-欧洲杯下注买球网站|【​网址​🎉ac10.net🎉​】
brendonbrash97589
 
PPTX
欧洲杯买球-欧洲杯买球投注网-欧洲杯买球投注网站|【​网址​🎉ac44.net🎉​】
rodriguezkiko995
 
Loops and functions in r
manikanta361
 
Unit I - 1R introduction to R program.pptx
SreeLaya9
 
R programming
Pramodkumar Jha
 
DataStructures.pptx
Thanuj Pothula
 
R language introduction
Shashwat Shriparv
 
data frames.pptx
RacksaviR
 
Introduction To Programming In R for data analyst
ssuser26ff68
 
Introduction to R for beginners
Abishek Purushothaman
 
Learning notes of r for python programmer (Temp1)
Chia-Chi Chang
 
Programming in R
Smruti Sarangi
 
Get started with R lang
senthil0809
 
[1062BPY12001] Data analysis with R / week 2
Kevin Chun-Hsien Hsu
 
世预赛买球-世预赛买球比赛投注-世预赛买球比赛投注官网|【​网址​🎉ac10.net🎉​】
bljeremy734
 
世预赛买球-世预赛买球竞彩平台-世预赛买球竞猜平台|【​网址​🎉ac123.net🎉​】
hanniaarias53
 
美洲杯买球-美洲杯买球怎么押注-美洲杯买球押注怎么玩|【​网址​🎉ac99.net🎉​】
kokoparmod677
 
欧洲杯体彩-欧洲杯体彩比赛投注-欧洲杯体彩比赛投注官网|【​网址​🎉ac99.net🎉​】
lopezkatherina914
 
世预赛投注-世预赛投注投注官网app-世预赛投注官网app下载|【​网址​🎉ac123.net🎉​】
bljeremy734
 
欧洲杯足彩-欧洲杯足彩线上体育买球-欧洲杯足彩买球推荐网站|【​网址​🎉ac55.net🎉​】
brunasordi905
 
欧洲杯下注-欧洲杯下注买球网-欧洲杯下注买球网站|【​网址​🎉ac10.net🎉​】
brendonbrash97589
 
欧洲杯买球-欧洲杯买球投注网-欧洲杯买球投注网站|【​网址​🎉ac44.net🎉​】
rodriguezkiko995
 
Ad

More from Vladimir Bakhrushin (20)

PPT
Decision-making on assessment of higher education institutions under uncertainty
Vladimir Bakhrushin
 
PPT
Якими бути стандартам вищої освіти для докторів філософії
Vladimir Bakhrushin
 
PPT
Академічна автономія і трансформація української освіти
Vladimir Bakhrushin
 
PPT
Оптимізація в освіті і управлінні
Vladimir Bakhrushin
 
PPTX
Мій 2015
Vladimir Bakhrushin
 
PPT
Українські університети: Сучасні виклики та можливі відповіді
Vladimir Bakhrushin
 
PPT
Два проекти закону україни
Vladimir Bakhrushin
 
PPT
Окремі аспекти реформування освіти України з погляду системного підходу
Vladimir Bakhrushin
 
PPT
Decision-making in education based on multi-criteria ranking of alternatives
Vladimir Bakhrushin
 
PPT
Деякі проблеми прийняття рішень в освіті
Vladimir Bakhrushin
 
PPTX
Закон про освіту
Vladimir Bakhrushin
 
PPT
Описова статистика в R
Vladimir Bakhrushin
 
PPT
Деякі графічні засоби R
Vladimir Bakhrushin
 
PPT
Plot function in R
Vladimir Bakhrushin
 
PPT
Функція plot() в R
Vladimir Bakhrushin
 
PPT
Робота з файлами даних в R, блоки виразів, цикли, функції
Vladimir Bakhrushin
 
PPT
Cluster analysis using k-means method in R
Vladimir Bakhrushin
 
PPT
Нові застосування статистичних методів в прикладних дослідженнях
Vladimir Bakhrushin
 
PPT
Парадоксы голосования
Vladimir Bakhrushin
 
PPT
Starting work with R
Vladimir Bakhrushin
 
Decision-making on assessment of higher education institutions under uncertainty
Vladimir Bakhrushin
 
Якими бути стандартам вищої освіти для докторів філософії
Vladimir Bakhrushin
 
Академічна автономія і трансформація української освіти
Vladimir Bakhrushin
 
Оптимізація в освіті і управлінні
Vladimir Bakhrushin
 
Мій 2015
Vladimir Bakhrushin
 
Українські університети: Сучасні виклики та можливі відповіді
Vladimir Bakhrushin
 
Два проекти закону україни
Vladimir Bakhrushin
 
Окремі аспекти реформування освіти України з погляду системного підходу
Vladimir Bakhrushin
 
Decision-making in education based on multi-criteria ranking of alternatives
Vladimir Bakhrushin
 
Деякі проблеми прийняття рішень в освіті
Vladimir Bakhrushin
 
Закон про освіту
Vladimir Bakhrushin
 
Описова статистика в R
Vladimir Bakhrushin
 
Деякі графічні засоби R
Vladimir Bakhrushin
 
Plot function in R
Vladimir Bakhrushin
 
Функція plot() в R
Vladimir Bakhrushin
 
Робота з файлами даних в R, блоки виразів, цикли, функції
Vladimir Bakhrushin
 
Cluster analysis using k-means method in R
Vladimir Bakhrushin
 
Нові застосування статистичних методів в прикладних дослідженнях
Vladimir Bakhrushin
 
Парадоксы голосования
Vladimir Bakhrushin
 
Starting work with R
Vladimir Bakhrushin
 
Ad

Recently uploaded (20)

PPTX
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
PPTX
Presentation: Climate Citizenship Digital Education
Karl Donert
 
PPTX
SCHOOL-BASED SEXUAL HARASSMENT PREVENTION AND RESPONSE WORKSHOP
komlalokoe
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
 
PDF
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
PPTX
Nutri-QUIZ-Bee-Elementary.pptx...................
ferdinandsanbuenaven
 
PPTX
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PPTX
HEAD INJURY IN CHILDREN: NURSING MANAGEMENGT.pptx
PRADEEP ABOTHU
 
PPTX
ROLE OF ANTIOXIDANT IN EYE HEALTH MANAGEMENT.pptx
Subham Panja
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
Presentation: Climate Citizenship Digital Education
Karl Donert
 
SCHOOL-BASED SEXUAL HARASSMENT PREVENTION AND RESPONSE WORKSHOP
komlalokoe
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
 
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
Nutri-QUIZ-Bee-Elementary.pptx...................
ferdinandsanbuenaven
 
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
HEAD INJURY IN CHILDREN: NURSING MANAGEMENGT.pptx
PRADEEP ABOTHU
 
ROLE OF ANTIOXIDANT IN EYE HEALTH MANAGEMENT.pptx
Subham Panja
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
community health nursing question paper 2.pdf
Prince kumar
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 

Files,blocks and functions in R

  • 1. DATA FILES, BLOCKS OF EXPRESSIONS, CYCLES AND FUNCTIONS IN R Vladimir Bakhrushin, Professor, D.Sc. (Phys. & Math.) [email protected]
  • 2. Data reading > data<-read.table(“File name", sep=";", dec=",", header=TRUE, …)  first argument is a reference to the file of *.csv format, that contains data;  argument sep indicates, by which sign the data are separated;  argument dec indicates decimal separator for numbers;  argument header indicates whether the first cells of each column are the column names;  argument row.names indicates whether one of columns contains the row names;  argument nrows specifies the number of lines that need to be read from the table.
  • 4. Writing data to a file write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ", na = "NA", dec = ".", row.names = TRUE, col.names = TRUE, qmethod = c("escape", "double"), …)  x – object that must be written to the file (usually it is a matrix or data table);  file – name of the file to which the data must be written or other connections opened to writing;  append – argument that indicates the need to append data to an existing file or to create a new file with the same name;  quote – indicates the need to take in quotes marks of rows and columns;  na – character set used for the missing values.
  • 5. Writing data to a file write.table(a2, file = "a2.csv", sep = " ", dec = ".")
  • 6. Lists For saving of heterogeneous data in the one object lists can be used. For example: > x1 = c("Milk", "Yogurt", "Sour cream", "Curd") > x2 = c(1, 1, 14, 7) > x3 = c(TRUE, FALSE) > l1 = list(Text = x1, Number = x2, Logic = x3) > l1 To identify specific elements of the list such constructions can be used :  l1$Text[3]; l1$Text;  l1[[1]][2]; l1[[2]].
  • 9. Data editing using function fix()
  • 10. Comments, blocks of expressions Any comment begins with the character #. The test located in the line after this character not regarded as part of the program to be executed. Expressions can be combined into blocks with curly braces. The result of the expressions block is the result of the last of them. > { + x = 9; + y = 4; + x + y; + } [1] 13
  • 11. Conditional constructs “If” – “else” statement is an example of conditional construct: if (<condition>) {<expression_1> }else{ <expression_2>}
  • 12. Loops Loops with predetermined number of iterations can be organized using function “for”: for (<variable> in <expression_1>) <expression_2> If it is need to repeat iterations until a certain condition is fulfilled, we can use a loop “while”: while (<condition>) { <expression> }
  • 13. Loops
  • 14. Loops Infinite loops “Repeat” are used when a procedure should be executed if the interruption condition is not performed. Command “break” is used to interrupt the cycle, and command “next” – to interrupt the current iteration and move to the next one.
  • 15. Functions Function in R is an object, that for a given set of arguments returns a certain value. Usually when the function is declared its value is assigned to some variable. <variabe> = function(<arguments>) { <expression> }. Subsequently, the function can be called using the construction: <result> = <variable>(<arguments>).
  • 18. Literature 1. An Introduction to R 2. Introduction to the R Language: Functions 3. R Tutorial: An R introduction to statistics 4. Kelly Black. R Tutorial