SlideShare a Scribd company logo
1 of 14
Programare in “R”
Ce este limbajul R ?
• Este un limbaj de scripting folosit pentru
  manipularea si analiza datelor statistice, inspirat
  dupa un alt limbaj de programare, folosit in
  statistica ,“S”, dezvoltat de AT&T.
De ce “R” ?
• este open-source, poate fi implementat in domeniile
  publice alaturi de limbajul statistic “S”,
• ca performanta este comparabil cu limbajele si
  produsele comerciale de programare, de cele mai multe
  ori fiind mult mai bun ,
• disponibil atat pentru Windows, Mac, Linux,
• ca orice limbaj de programare permite crearea unor
  functii pentru a automatiza analizele efectuate,
• are o strucura de programare orientata pe obiect.
Un prim exercitiu
Crearea un set simplu de date, adica un vector care sa contina
  numerele 1, 2 si 3, denumit x:

>x <- c(1,2,3)

Operatorul standard de atribuire este “<-” sau ‘’=‘’, sau functia
  assign().

In loc de cifre se pot pune chiar si litere

>y <- c(“a”,”b”,”c”)

sau chiar combinatii.

>z <- c(“a”,13, “c”).
O data cu instalarea programului puteti beneficia de existenta unor seturi de
   date pe care le puteti folosi. Pentru aceasta folositi functia data() :
>data()

>Nile – set de date deja existent

Plotarea unei histograme a acestui set se face utilizand functia hist() :

>hist(Nile)

>?hist – manual pentru aceasta functie
>help(hist) - //-

Editarea unui set de date se face cu functia edit()

>edit(Nile)
Structurile de date cu care lucreaza
              limbajul R
• Vectori
>x <- c(1,2,3)

• Matrice – tehnic este un vector ce contine
  2 atribute –nr de randuri si de coloane:

• > y <- matrix(c(1,2,3,4),nrow=2,ncol=2)
• >y
Sintaxa “matrix” este o functie ce creaza o
  matrice care contine 2 vectori, vectorii fiind
  stocati in “y”.
• Liste - structuri de date a caror continut
  pot fi elemente din diverse tipuri de date si
  sunt reprezentate prin semnul “$”
>x$u- se traduce prin: este “u” componenta
  listei “X” ?

• Data frames –liste a caror vectori
  corespund unor coloane dintr-o matrice
Vectori

Pot fi:
• Numere intregi(integer)
• Zecimale (floating)
• Caractere (string)
• Expresii logice (bollean)
• Complexe
• Obiecte
Exemple:
Lungimea unui vector poate fi obtinuta cu ajutorul functiei length():
>length(x)

Atribuirea valorilor sau declararea lor

>y <- c(5,12)

sau

> y <- vector(length=2) - declararea vectorului
> y[1] <- 5
>y[2] <- 12

Operatorii      “:”   seq() si rep()

Operatorul “:” genereaza o serie consecutiva de valori crescatoare sau descrecatoare

>5:9
[1] 5 6 7 8 9

> 5:1
[1] 5 4 3 2 1
•   Operatorul seq() (secventa) genereaza o secventa aritmetica

>seq(3,7)
[1] 3 4 5 6 7

> seq(12,30,3)
[1] 12 15 18 21 24 27 30

Operatorul rep() (“repeat”) –repeta

>x <- rep(7,4)

>x
[1] 7 7 7 7

>rep(1:3,2)

[1] 1 2 3 1 2 3
Operatii logice cu vectori
• Puteti adauga vectori:

>x <- c(1,2,4)
> x + c(5,0,-1)
• [1] 6 2 3

Functiile any() si all():
>x <- 1:10

> if (any(x > 8)) print("exista cel putin un numar mai mare decat 8")
[1] " exista cel putin un numar mai mare decat 8 “

>if (all(x < 10)) print("Toate sunt mai mici ca 10")
Indexarea vectorilor

> y <- c(1.2,3.9,0.4,0.12)
> y[c(1,3)]
[1] 1.2 0.4
>y[2:3]
[1] 3.9 0.4
> z <- c(5,12,13)
 z[-1] # exclude elementul 1
[1] 12 13
Denumirea vectorilor
• Vectorii pot fi denumiti cu anumite acronime, folosind
  functia name():
>x <- c(1,2,4)
>names(x)
• NULL
> names(x) <- c("a","b","ab")
> names(x)
• [1] "a" "b" "ab"
>x
• a b ab
• 124
Expresii de date logice

> z <- c(5,2,-3,8)
>z
[1] 5 2 -3 8
> z*z > 8
[1] TRUE FALSE TRUE TRUE

More Related Content

Recently uploaded

Catalogul firmei de exercițiu Ancolex 2024.pptx
Catalogul firmei de exercițiu Ancolex 2024.pptxCatalogul firmei de exercițiu Ancolex 2024.pptx
Catalogul firmei de exercițiu Ancolex 2024.pptxCori Rus
 
Strategii-pentru-educatia-remedială-ppt.pptx
Strategii-pentru-educatia-remedială-ppt.pptxStrategii-pentru-educatia-remedială-ppt.pptx
Strategii-pentru-educatia-remedială-ppt.pptxMoroianuCristina1
 
Agricultura- lectie predare -invatare geografie cls 10
Agricultura- lectie predare -invatare geografie cls 10Agricultura- lectie predare -invatare geografie cls 10
Agricultura- lectie predare -invatare geografie cls 10CrciunAndreeaMaria
 
Igiena sistemului digestiv , biologi clasa 11-a
Igiena sistemului digestiv , biologi clasa 11-aIgiena sistemului digestiv , biologi clasa 11-a
Igiena sistemului digestiv , biologi clasa 11-aCMB
 
Sistemul excretor la om, biologie clasa 11
Sistemul excretor la om, biologie clasa 11Sistemul excretor la om, biologie clasa 11
Sistemul excretor la om, biologie clasa 11CMB
 
ziua pamantului ziua pamantului ziua pamantului
ziua pamantului ziua pamantului ziua pamantuluiziua pamantului ziua pamantului ziua pamantului
ziua pamantului ziua pamantului ziua pamantuluiAndr808555
 

Recently uploaded (6)

Catalogul firmei de exercițiu Ancolex 2024.pptx
Catalogul firmei de exercițiu Ancolex 2024.pptxCatalogul firmei de exercițiu Ancolex 2024.pptx
Catalogul firmei de exercițiu Ancolex 2024.pptx
 
Strategii-pentru-educatia-remedială-ppt.pptx
Strategii-pentru-educatia-remedială-ppt.pptxStrategii-pentru-educatia-remedială-ppt.pptx
Strategii-pentru-educatia-remedială-ppt.pptx
 
Agricultura- lectie predare -invatare geografie cls 10
Agricultura- lectie predare -invatare geografie cls 10Agricultura- lectie predare -invatare geografie cls 10
Agricultura- lectie predare -invatare geografie cls 10
 
Igiena sistemului digestiv , biologi clasa 11-a
Igiena sistemului digestiv , biologi clasa 11-aIgiena sistemului digestiv , biologi clasa 11-a
Igiena sistemului digestiv , biologi clasa 11-a
 
Sistemul excretor la om, biologie clasa 11
Sistemul excretor la om, biologie clasa 11Sistemul excretor la om, biologie clasa 11
Sistemul excretor la om, biologie clasa 11
 
ziua pamantului ziua pamantului ziua pamantului
ziua pamantului ziua pamantului ziua pamantuluiziua pamantului ziua pamantului ziua pamantului
ziua pamantului ziua pamantului ziua pamantului
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Programare r 1

  • 2. Ce este limbajul R ? • Este un limbaj de scripting folosit pentru manipularea si analiza datelor statistice, inspirat dupa un alt limbaj de programare, folosit in statistica ,“S”, dezvoltat de AT&T.
  • 3. De ce “R” ? • este open-source, poate fi implementat in domeniile publice alaturi de limbajul statistic “S”, • ca performanta este comparabil cu limbajele si produsele comerciale de programare, de cele mai multe ori fiind mult mai bun , • disponibil atat pentru Windows, Mac, Linux, • ca orice limbaj de programare permite crearea unor functii pentru a automatiza analizele efectuate, • are o strucura de programare orientata pe obiect.
  • 4. Un prim exercitiu Crearea un set simplu de date, adica un vector care sa contina numerele 1, 2 si 3, denumit x: >x <- c(1,2,3) Operatorul standard de atribuire este “<-” sau ‘’=‘’, sau functia assign(). In loc de cifre se pot pune chiar si litere >y <- c(“a”,”b”,”c”) sau chiar combinatii. >z <- c(“a”,13, “c”).
  • 5. O data cu instalarea programului puteti beneficia de existenta unor seturi de date pe care le puteti folosi. Pentru aceasta folositi functia data() : >data() >Nile – set de date deja existent Plotarea unei histograme a acestui set se face utilizand functia hist() : >hist(Nile) >?hist – manual pentru aceasta functie >help(hist) - //- Editarea unui set de date se face cu functia edit() >edit(Nile)
  • 6. Structurile de date cu care lucreaza limbajul R • Vectori >x <- c(1,2,3) • Matrice – tehnic este un vector ce contine 2 atribute –nr de randuri si de coloane: • > y <- matrix(c(1,2,3,4),nrow=2,ncol=2) • >y
  • 7. Sintaxa “matrix” este o functie ce creaza o matrice care contine 2 vectori, vectorii fiind stocati in “y”. • Liste - structuri de date a caror continut pot fi elemente din diverse tipuri de date si sunt reprezentate prin semnul “$” >x$u- se traduce prin: este “u” componenta listei “X” ? • Data frames –liste a caror vectori corespund unor coloane dintr-o matrice
  • 8. Vectori Pot fi: • Numere intregi(integer) • Zecimale (floating) • Caractere (string) • Expresii logice (bollean) • Complexe • Obiecte
  • 9. Exemple: Lungimea unui vector poate fi obtinuta cu ajutorul functiei length(): >length(x) Atribuirea valorilor sau declararea lor >y <- c(5,12) sau > y <- vector(length=2) - declararea vectorului > y[1] <- 5 >y[2] <- 12 Operatorii “:” seq() si rep() Operatorul “:” genereaza o serie consecutiva de valori crescatoare sau descrecatoare >5:9 [1] 5 6 7 8 9 > 5:1 [1] 5 4 3 2 1
  • 10. Operatorul seq() (secventa) genereaza o secventa aritmetica >seq(3,7) [1] 3 4 5 6 7 > seq(12,30,3) [1] 12 15 18 21 24 27 30 Operatorul rep() (“repeat”) –repeta >x <- rep(7,4) >x [1] 7 7 7 7 >rep(1:3,2) [1] 1 2 3 1 2 3
  • 11. Operatii logice cu vectori • Puteti adauga vectori: >x <- c(1,2,4) > x + c(5,0,-1) • [1] 6 2 3 Functiile any() si all(): >x <- 1:10 > if (any(x > 8)) print("exista cel putin un numar mai mare decat 8") [1] " exista cel putin un numar mai mare decat 8 “ >if (all(x < 10)) print("Toate sunt mai mici ca 10")
  • 12. Indexarea vectorilor > y <- c(1.2,3.9,0.4,0.12) > y[c(1,3)] [1] 1.2 0.4 >y[2:3] [1] 3.9 0.4 > z <- c(5,12,13)  z[-1] # exclude elementul 1 [1] 12 13
  • 13. Denumirea vectorilor • Vectorii pot fi denumiti cu anumite acronime, folosind functia name(): >x <- c(1,2,4) >names(x) • NULL > names(x) <- c("a","b","ab") > names(x) • [1] "a" "b" "ab" >x • a b ab • 124
  • 14. Expresii de date logice > z <- c(5,2,-3,8) >z [1] 5 2 -3 8 > z*z > 8 [1] TRUE FALSE TRUE TRUE