際際滷

際際滷Share a Scribd company logo
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 (18)

10 Conspect normativ C 16 normativ timp friguros.pptx
10 Conspect normativ C 16 normativ timp friguros.pptx10 Conspect normativ C 16 normativ timp friguros.pptx
10 Conspect normativ C 16 normativ timp friguros.pptx
AdrianBucin
10 Conspect normativ C 16 timp friguros.pptx
10 Conspect normativ C 16 timp friguros.pptx10 Conspect normativ C 16 timp friguros.pptx
10 Conspect normativ C 16 timp friguros.pptx
AdrianBucin
Antreprenoriat prin firma de exercitiu
Antreprenoriat prin firma de exercitiuAntreprenoriat prin firma de exercitiu
Antreprenoriat prin firma de exercitiu
Rodica B
Dezvoltarea personala, proiect didactic penrtu clasa a opta
Dezvoltarea personala, proiect didactic penrtu clasa a optaDezvoltarea personala, proiect didactic penrtu clasa a opta
Dezvoltarea personala, proiect didactic penrtu clasa a opta
AndreaGrosu
5 Conspect normativ I7 actualizat cu modificari 2023.pptx
5 Conspect normativ I7 actualizat cu modificari 2023.pptx5 Conspect normativ I7 actualizat cu modificari 2023.pptx
5 Conspect normativ I7 actualizat cu modificari 2023.pptx
AdrianBucin
......Anotimpurile - Prezentare PPT......
......Anotimpurile - Prezentare PPT............Anotimpurile - Prezentare PPT......
......Anotimpurile - Prezentare PPT......
epikmatei
10 Conspect normativ C 16 normativ timp friguros.pptx
10 Conspect normativ C 16 normativ timp friguros.pptx10 Conspect normativ C 16 normativ timp friguros.pptx
10 Conspect normativ C 16 normativ timp friguros.pptx
AdrianBucin
Patrimoniul cultural al Republicii Moldova
Patrimoniul cultural al Republicii MoldovaPatrimoniul cultural al Republicii Moldova
Patrimoniul cultural al Republicii Moldova
HanteaLarisa
Sub. 1 Metode de determinare a refractiei.pptx
Sub. 1 Metode de determinare a refractiei.pptxSub. 1 Metode de determinare a refractiei.pptx
Sub. 1 Metode de determinare a refractiei.pptx
ralucaevelina1
Chestionare firma de exerciiu
Chestionare firma de exerciiu Chestionare firma de exerciiu
Chestionare firma de exerciiu
Rodica B
APELE DE SUPRAFA ALE AFRICII.pptx58942
APELE DE SUPRAFA ALE AFRICII.pptx58942APELE DE SUPRAFA ALE AFRICII.pptx58942
APELE DE SUPRAFA ALE AFRICII.pptx58942
NataliaBrinza1
06.contribu_comuni.pdfvgggryuujhhvbhjjjhh
06.contribu_comuni.pdfvgggryuujhhvbhjjjhh06.contribu_comuni.pdfvgggryuujhhvbhjjjhh
06.contribu_comuni.pdfvgggryuujhhvbhjjjhh
GbrielaKim
2 Teste tip chestionar legislatie HG si legi.pptx
2 Teste tip chestionar legislatie HG si legi.pptx2 Teste tip chestionar legislatie HG si legi.pptx
2 Teste tip chestionar legislatie HG si legi.pptx
AdrianBucin
Individul ca 樽ntreprinztor
Individul ca 樽ntreprinztorIndividul ca 樽ntreprinztor
Individul ca 樽ntreprinztor
Rodica B
85579145-酷看恢庄温-界看鉛温姻-庄-温稼恰庄艶岳温岳艶温-鉛温-界看沿庄庄-庄-温糸看鉛艶壊界艶稼釘庄.沿沿岳
85579145-酷看恢庄温-界看鉛温姻-庄-温稼恰庄艶岳温岳艶温-鉛温-界看沿庄庄-庄-温糸看鉛艶壊界艶稼釘庄.沿沿岳85579145-酷看恢庄温-界看鉛温姻-庄-温稼恰庄艶岳温岳艶温-鉛温-界看沿庄庄-庄-温糸看鉛艶壊界艶稼釘庄.沿沿岳
85579145-酷看恢庄温-界看鉛温姻-庄-温稼恰庄艶岳温岳艶温-鉛温-界看沿庄庄-庄-温糸看鉛艶壊界艶稼釘庄.沿沿岳
AndreaGrosu
0 padurile ecuatoriale.ppt geografie lectie
0 padurile ecuatoriale.ppt geografie lectie0 padurile ecuatoriale.ppt geografie lectie
0 padurile ecuatoriale.ppt geografie lectie
NataliaBrinza1
10 Conspect normativ C 16 normativ timp friguros.pptx
10 Conspect normativ C 16 normativ timp friguros.pptx10 Conspect normativ C 16 normativ timp friguros.pptx
10 Conspect normativ C 16 normativ timp friguros.pptx
AdrianBucin
Studiu de caz 30 RTE Instalatii electrice.pdf
Studiu de caz 30 RTE Instalatii electrice.pdfStudiu de caz 30 RTE Instalatii electrice.pdf
Studiu de caz 30 RTE Instalatii electrice.pdf
AdrianBucin
10 Conspect normativ C 16 normativ timp friguros.pptx
10 Conspect normativ C 16 normativ timp friguros.pptx10 Conspect normativ C 16 normativ timp friguros.pptx
10 Conspect normativ C 16 normativ timp friguros.pptx
AdrianBucin
10 Conspect normativ C 16 timp friguros.pptx
10 Conspect normativ C 16 timp friguros.pptx10 Conspect normativ C 16 timp friguros.pptx
10 Conspect normativ C 16 timp friguros.pptx
AdrianBucin
Antreprenoriat prin firma de exercitiu
Antreprenoriat prin firma de exercitiuAntreprenoriat prin firma de exercitiu
Antreprenoriat prin firma de exercitiu
Rodica B
Dezvoltarea personala, proiect didactic penrtu clasa a opta
Dezvoltarea personala, proiect didactic penrtu clasa a optaDezvoltarea personala, proiect didactic penrtu clasa a opta
Dezvoltarea personala, proiect didactic penrtu clasa a opta
AndreaGrosu
5 Conspect normativ I7 actualizat cu modificari 2023.pptx
5 Conspect normativ I7 actualizat cu modificari 2023.pptx5 Conspect normativ I7 actualizat cu modificari 2023.pptx
5 Conspect normativ I7 actualizat cu modificari 2023.pptx
AdrianBucin
......Anotimpurile - Prezentare PPT......
......Anotimpurile - Prezentare PPT............Anotimpurile - Prezentare PPT......
......Anotimpurile - Prezentare PPT......
epikmatei
10 Conspect normativ C 16 normativ timp friguros.pptx
10 Conspect normativ C 16 normativ timp friguros.pptx10 Conspect normativ C 16 normativ timp friguros.pptx
10 Conspect normativ C 16 normativ timp friguros.pptx
AdrianBucin
Patrimoniul cultural al Republicii Moldova
Patrimoniul cultural al Republicii MoldovaPatrimoniul cultural al Republicii Moldova
Patrimoniul cultural al Republicii Moldova
HanteaLarisa
Sub. 1 Metode de determinare a refractiei.pptx
Sub. 1 Metode de determinare a refractiei.pptxSub. 1 Metode de determinare a refractiei.pptx
Sub. 1 Metode de determinare a refractiei.pptx
ralucaevelina1
Chestionare firma de exerciiu
Chestionare firma de exerciiu Chestionare firma de exerciiu
Chestionare firma de exerciiu
Rodica B
APELE DE SUPRAFA ALE AFRICII.pptx58942
APELE DE SUPRAFA ALE AFRICII.pptx58942APELE DE SUPRAFA ALE AFRICII.pptx58942
APELE DE SUPRAFA ALE AFRICII.pptx58942
NataliaBrinza1
06.contribu_comuni.pdfvgggryuujhhvbhjjjhh
06.contribu_comuni.pdfvgggryuujhhvbhjjjhh06.contribu_comuni.pdfvgggryuujhhvbhjjjhh
06.contribu_comuni.pdfvgggryuujhhvbhjjjhh
GbrielaKim
2 Teste tip chestionar legislatie HG si legi.pptx
2 Teste tip chestionar legislatie HG si legi.pptx2 Teste tip chestionar legislatie HG si legi.pptx
2 Teste tip chestionar legislatie HG si legi.pptx
AdrianBucin
Individul ca 樽ntreprinztor
Individul ca 樽ntreprinztorIndividul ca 樽ntreprinztor
Individul ca 樽ntreprinztor
Rodica B
85579145-酷看恢庄温-界看鉛温姻-庄-温稼恰庄艶岳温岳艶温-鉛温-界看沿庄庄-庄-温糸看鉛艶壊界艶稼釘庄.沿沿岳
85579145-酷看恢庄温-界看鉛温姻-庄-温稼恰庄艶岳温岳艶温-鉛温-界看沿庄庄-庄-温糸看鉛艶壊界艶稼釘庄.沿沿岳85579145-酷看恢庄温-界看鉛温姻-庄-温稼恰庄艶岳温岳艶温-鉛温-界看沿庄庄-庄-温糸看鉛艶壊界艶稼釘庄.沿沿岳
85579145-酷看恢庄温-界看鉛温姻-庄-温稼恰庄艶岳温岳艶温-鉛温-界看沿庄庄-庄-温糸看鉛艶壊界艶稼釘庄.沿沿岳
AndreaGrosu
0 padurile ecuatoriale.ppt geografie lectie
0 padurile ecuatoriale.ppt geografie lectie0 padurile ecuatoriale.ppt geografie lectie
0 padurile ecuatoriale.ppt geografie lectie
NataliaBrinza1
10 Conspect normativ C 16 normativ timp friguros.pptx
10 Conspect normativ C 16 normativ timp friguros.pptx10 Conspect normativ C 16 normativ timp friguros.pptx
10 Conspect normativ C 16 normativ timp friguros.pptx
AdrianBucin
Studiu de caz 30 RTE Instalatii electrice.pdf
Studiu de caz 30 RTE Instalatii electrice.pdfStudiu de caz 30 RTE Instalatii electrice.pdf
Studiu de caz 30 RTE Instalatii electrice.pdf
AdrianBucin

Featured (20)

2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design ProcessStorytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
Artificial Intelligence, Data and Competition SCHREPEL June 2024 OECD dis...
Artificial Intelligence, Data and Competition  SCHREPEL  June 2024 OECD dis...Artificial Intelligence, Data and Competition  SCHREPEL  June 2024 OECD dis...
Artificial Intelligence, Data and Competition SCHREPEL June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
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
Marius 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 ChatGPT
Expeed 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 Engineerings
Pixeldarts
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
ThinkNow
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
marketingartwork
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
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
Neil 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 2024
Albert 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 Insights
Kurio // 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 2024
Search 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 summary
SpeakerHub
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 Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design ProcessStorytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
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
Marius 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 ChatGPT
Expeed 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 Engineerings
Pixeldarts
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
ThinkNow
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
marketingartwork
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
Neil 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 2024
Albert 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 Insights
Kurio // 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 2024
Search 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 summary
SpeakerHub
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 Intent
Lily Ray

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