SlideShare una empresa de Scribd logo
1 de 34
I2R R Enviroment & Vettori
R statistical package ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
R prompt R version 2.6.1 (2007-11-26) Copyright (C) 2007 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos ,  'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. >
Usare R ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
R On-Line Help > help(mean)
R HTML Help System > help.start()
R demo > demo(graphics)
R: Valutazione di Espressioni ,[object Object],[object Object],[object Object],[object Object],In R  tutte le espressioni restituiscono un valore  ma il valore puo’ essere NULL o invisibile. Alcune espressioni sono importanti non per il loro risultato, ma per gli “effetti secondari” che generano, per esempio il comando: > help(mean) Non stampa niente a video, ma ha l’interessante effetto secondario di aprire la pagina help di R relativa al comando  mean
Linguaggio Object-Oriented ,[object Object],[object Object],[object Object],[object Object],[object Object],In R ogni cosa e’ un oggetto ed ogni oggetto appartiene ad una classe MyArray = new Array MyArray Class Array data function: pop function: push In R: S3 and S4 classes
Creazione di Oggetti in R ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Nomi di Variabili in R ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Workspace ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Working Directory ,[object Object],[object Object],[object Object],[object Object],> setwd("/Users/default/Desktop/R_DRAFT") > getwd() [1] "/Users/default/Desktop/R_DRAFT" > dir() [1] "LASTPRDM.txt"  "PRDM_27_3_2007.log"
Tipologie di Dati ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Vettori ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Vettori:  c()  and  length() ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Accedere agli elementi di un Vettore ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Inizializzazione e Riempimento ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Metodi per costruire un vettore in R ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Metodi per costruire un vettore:  scan() ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],copy paste <ENTER> <ENTER>
I vettori possono contenere  un solo tipo  di dati ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Indice di un Vettore ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 [14] [13] [12] [11] [10] [9] [8] [7] [6] [5] [4] [3] [2] [1]
Cercare elementi in un Vettore ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 [14] [13] [12] [11] [10] [9] [8] [7] [6] [5] [4] [3] [2] [1]
Operatori di comparazione e operatori logici Diverso da … Maggiore o uguale a … Minore o uguale a … Uguale a … Maggiore di … Minore di … Significato x != 2 != x >= 2 >= x <= 2 <= x == 2 == x > 2 > x < 2 < Esempio Operatore NOT OR AND Significato x > 2 ! x == 4 ! x > 2 | x == 0 | x < 2 & x != 0 & Esempio Operatore
Accedere agli elementi di un Vettore: altri comandi ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 [14] [13] [12] [11] [10] [9] [8] [7] [6] [5] [4] [3] [2] [1]
Valori mancanti (NA) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],> x <- c(NA,1,2,3,NA,NA) > x [1] NA  1  2  3 NA NA > is.na(x) [1] TRUE FALSE FALSE FALSE TRUE TRUE > which(is.na(x)) [1] 1 5 6 > x[!is.na(x)] [1] 1 2 3 > x <- c(NA,1,2,3,NA,NA) > mean(x) [1] NA > mean(x, na.rm=TRUE) [1] 2
La funzione mean:  na.rm > help(mean)
Operazioni algebriche ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],> help(Arithmetic)
Altre operazioni algebriche Coseno cos() Seno sin() Logaritmo in base 10 log10 Logaritmo in base 2 log2() Logaritmo log() Exponential function (e) exp() Valore assoluto abs() Radice quadrata sqrt()
Altre utili operazioni con i vettori ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],> y <- c(2,7,4,1) > y [1] 2 7 4 1 > rev(y) [1] 1 4 7 2 > sort(y) [1] 1 2 4 7 > rev(sort(y)) [1] 7 4 2 1 > sum(y) [1] 14 > sum(y[y>2]) [1] 11 > sum(y>2) [1] 2
Factors ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
NOTA: Espressioni e oggetti ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Espressioni e oggetti: polimorfismo ,[object Object],[object Object],[object Object],> x <- rnorm(100, mean=10,sd=2) > class(x) [1] &quot;numeric&quot; > summary(x) Min. 1st Qu.  Median  Mean 3rd Qu.  Max.  5.189  8.401  9.603  9.625  10.890  14.850  > x <- factor(vettore, levels=classi, ordered=T) > summary(x) giovane anziano  adulto  10  5  7
Utili operazioni di ricodifica ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Más contenido relacionado

La actualidad más candente

Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101
Raj Rajandran
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
dchuynh
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
arnolambert
 

La actualidad más candente (20)

Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Regular Expressions 101
Regular Expressions 101Regular Expressions 101
Regular Expressions 101
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Pointer to array and structure
Pointer to array and structurePointer to array and structure
Pointer to array and structure
 
vim - Tips and_tricks
vim - Tips and_tricksvim - Tips and_tricks
vim - Tips and_tricks
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
 
Regex Presentation
Regex PresentationRegex Presentation
Regex Presentation
 
Lesson 02 python keywords and identifiers
Lesson 02   python keywords and identifiersLesson 02   python keywords and identifiers
Lesson 02 python keywords and identifiers
 
File handling in C
File handling in CFile handling in C
File handling in C
 
Information Visualisation - Lecture 2
Information Visualisation - Lecture 2Information Visualisation - Lecture 2
Information Visualisation - Lecture 2
 
Control statement in c
Control statement in cControl statement in c
Control statement in c
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Linked list
Linked listLinked list
Linked list
 
canara bank Application form 2015
canara bank Application form 2015canara bank Application form 2015
canara bank Application form 2015
 
String In C Language
String In C Language String In C Language
String In C Language
 
Python programming : Control statements
Python programming : Control statementsPython programming : Control statements
Python programming : Control statements
 
Graphs in datastructures
Graphs in datastructuresGraphs in datastructures
Graphs in datastructures
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Chap 02-1
Chap 02-1Chap 02-1
Chap 02-1
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
 

Destacado

Introduzione a R
Introduzione a RIntroduzione a R
Introduzione a R
MCalderisi
 
Laboratorio Probabilidad 1/3
Laboratorio Probabilidad 1/3Laboratorio Probabilidad 1/3
Laboratorio Probabilidad 1/3
cbpresentaciones
 
Scheduling power-aware abstract
Scheduling power-aware abstractScheduling power-aware abstract
Scheduling power-aware abstract
Vincenzo De Maio
 
Introduction to R by David Lucy Cap 12-16
Introduction to R by David Lucy Cap 12-16Introduction to R by David Lucy Cap 12-16
Introduction to R by David Lucy Cap 12-16
Luis Pons
 
Ejercicios resueltos en r
Ejercicios resueltos en rEjercicios resueltos en r
Ejercicios resueltos en r
zasque11
 

Destacado (20)

PhD midterm report
PhD midterm reportPhD midterm report
PhD midterm report
 
R Graphics
R GraphicsR Graphics
R Graphics
 
Introduzione a R
Introduzione a RIntroduzione a R
Introduzione a R
 
Laboratorio Probabilidad 1/3
Laboratorio Probabilidad 1/3Laboratorio Probabilidad 1/3
Laboratorio Probabilidad 1/3
 
Linguaggio R, principi e concetti
Linguaggio R, principi e concettiLinguaggio R, principi e concetti
Linguaggio R, principi e concetti
 
R_note_ODE_ver1.0
R_note_ODE_ver1.0R_note_ODE_ver1.0
R_note_ODE_ver1.0
 
Elisa Teodoro, Clase 5, Funciones
Elisa Teodoro, Clase 5, FuncionesElisa Teodoro, Clase 5, Funciones
Elisa Teodoro, Clase 5, Funciones
 
Ruby es un lenguaje de programación interpretado
Ruby es un lenguaje de programación interpretadoRuby es un lenguaje de programación interpretado
Ruby es un lenguaje de programación interpretado
 
Grafici
GraficiGrafici
Grafici
 
Scheduling power-aware abstract
Scheduling power-aware abstractScheduling power-aware abstract
Scheduling power-aware abstract
 
Elisa Teodoro, Aplicacion de Derivadas, Clase 2
Elisa Teodoro, Aplicacion de Derivadas, Clase 2Elisa Teodoro, Aplicacion de Derivadas, Clase 2
Elisa Teodoro, Aplicacion de Derivadas, Clase 2
 
Programacion en R
Programacion en RProgramacion en R
Programacion en R
 
Abstract tesi
Abstract tesiAbstract tesi
Abstract tesi
 
Introduction to R by David Lucy Cap 12-16
Introduction to R by David Lucy Cap 12-16Introduction to R by David Lucy Cap 12-16
Introduction to R by David Lucy Cap 12-16
 
ECUACIONES DIFERENCIALES CON DERIVE
ECUACIONES DIFERENCIALES CON DERIVEECUACIONES DIFERENCIALES CON DERIVE
ECUACIONES DIFERENCIALES CON DERIVE
 
9 introduzione r
9   introduzione r9   introduzione r
9 introduzione r
 
Ejercicios resueltos en r
Ejercicios resueltos en rEjercicios resueltos en r
Ejercicios resueltos en r
 
An introduction to structural equation models in R using the Lavaan package
An introduction to structural equation models in R using the Lavaan packageAn introduction to structural equation models in R using the Lavaan package
An introduction to structural equation models in R using the Lavaan package
 
Apuntes de prácticas de DERIVE
Apuntes de prácticas de DERIVEApuntes de prácticas de DERIVE
Apuntes de prácticas de DERIVE
 
LENGUAJE DE PROGRAMACION R
LENGUAJE DE PROGRAMACION RLENGUAJE DE PROGRAMACION R
LENGUAJE DE PROGRAMACION R
 

Similar a R Vectors

Esercitazione 3 (14 marzo 2012)
Esercitazione 3 (14 marzo 2012)Esercitazione 3 (14 marzo 2012)
Esercitazione 3 (14 marzo 2012)
STELITANO
 
Esercitazione 1 (27 febbraio 2012)
Esercitazione 1 (27 febbraio 2012)Esercitazione 1 (27 febbraio 2012)
Esercitazione 1 (27 febbraio 2012)
STELITANO
 
Lezione 16 (2 aprile 2012)
Lezione 16 (2 aprile 2012)Lezione 16 (2 aprile 2012)
Lezione 16 (2 aprile 2012)
STELITANO
 
5 Strutture Iterative
5   Strutture Iterative5   Strutture Iterative
5 Strutture Iterative
guest60e9511
 

Similar a R Vectors (20)

Riepilogo Java C/C++
Riepilogo Java C/C++Riepilogo Java C/C++
Riepilogo Java C/C++
 
What is new in C# 2018
What is new in C# 2018What is new in C# 2018
What is new in C# 2018
 
Esercitazione 3 (14 marzo 2012)
Esercitazione 3 (14 marzo 2012)Esercitazione 3 (14 marzo 2012)
Esercitazione 3 (14 marzo 2012)
 
7 Sottoprogrammi
7   Sottoprogrammi7   Sottoprogrammi
7 Sottoprogrammi
 
08 mapreduce
08   mapreduce08   mapreduce
08 mapreduce
 
Array
ArrayArray
Array
 
Esercitazione 1 (27 febbraio 2012)
Esercitazione 1 (27 febbraio 2012)Esercitazione 1 (27 febbraio 2012)
Esercitazione 1 (27 febbraio 2012)
 
What's new in C# 7
What's new in C# 7What's new in C# 7
What's new in C# 7
 
La Grafica Con Java
La Grafica Con JavaLa Grafica Con Java
La Grafica Con Java
 
Lezione 16 (2 aprile 2012)
Lezione 16 (2 aprile 2012)Lezione 16 (2 aprile 2012)
Lezione 16 (2 aprile 2012)
 
Inferno Limbo Italian
Inferno Limbo ItalianInferno Limbo Italian
Inferno Limbo Italian
 
Introduzione a Latex
Introduzione a LatexIntroduzione a Latex
Introduzione a Latex
 
Strutture dati 04-funzionicustom-classioggetti
Strutture dati 04-funzionicustom-classioggettiStrutture dati 04-funzionicustom-classioggetti
Strutture dati 04-funzionicustom-classioggetti
 
Spyppolare o non spyppolare
Spyppolare o non spyppolareSpyppolare o non spyppolare
Spyppolare o non spyppolare
 
Pycrashcourse
PycrashcoursePycrashcourse
Pycrashcourse
 
Data mining 04-funzionicustom-classioggetti
Data mining 04-funzionicustom-classioggettiData mining 04-funzionicustom-classioggetti
Data mining 04-funzionicustom-classioggetti
 
Rest sdk
Rest sdkRest sdk
Rest sdk
 
5 Strutture Iterative
5   Strutture Iterative5   Strutture Iterative
5 Strutture Iterative
 
Modulo 1 - Lezione 1
Modulo 1 - Lezione 1Modulo 1 - Lezione 1
Modulo 1 - Lezione 1
 
Introduzione a scala prima parte
Introduzione a scala   prima parteIntroduzione a scala   prima parte
Introduzione a scala prima parte
 

R Vectors

  • 1. I2R R Enviroment & Vettori
  • 2.
  • 3. R prompt R version 2.6.1 (2007-11-26) Copyright (C) 2007 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos , 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. >
  • 4.
  • 5. R On-Line Help > help(mean)
  • 6. R HTML Help System > help.start()
  • 7. R demo > demo(graphics)
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24. Operatori di comparazione e operatori logici Diverso da … Maggiore o uguale a … Minore o uguale a … Uguale a … Maggiore di … Minore di … Significato x != 2 != x >= 2 >= x <= 2 <= x == 2 == x > 2 > x < 2 < Esempio Operatore NOT OR AND Significato x > 2 ! x == 4 ! x > 2 | x == 0 | x < 2 & x != 0 & Esempio Operatore
  • 25.
  • 26.
  • 27. La funzione mean: na.rm > help(mean)
  • 28.
  • 29. Altre operazioni algebriche Coseno cos() Seno sin() Logaritmo in base 10 log10 Logaritmo in base 2 log2() Logaritmo log() Exponential function (e) exp() Valore assoluto abs() Radice quadrata sqrt()
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.