Dispensa di modelli lineari in R - Dipartimento di Statistica
Dispensa di modelli lineari in R - Dipartimento di Statistica
Dispensa di modelli lineari in R - Dipartimento di Statistica
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
CAPITOLO 1. RICHIAMI DI R 11<br />
> x[3, ]<br />
[1] 5 13<br />
Possono essere estratti sotto<strong>in</strong>siemi <strong>di</strong> righe e/o colonne.<br />
> x x<br />
[,1] [,2] [,3] [,4]<br />
[1,] 1 5 9 13<br />
[2,] 2 6 10 14<br />
[3,] 3 7 11 15<br />
[4,] 4 8 12 16<br />
> x[c(1, 4), c(3, 4)]<br />
[,1] [,2]<br />
[1,] 9 13<br />
[2,] 12 16<br />
1.4 Data frame<br />
Un data frame è un oggetto simile ad una matrice usato per rappresentare una matrice<br />
<strong>di</strong> dati. In un data frame, ogni riga rappresenta una unità statistica ed ogni colonna<br />
rappresenta una variabile. Le colonne possono contenere variabili quantitative<br />
o qualitative.<br />
Per leggere una matrice <strong>di</strong> dati da file esterno, si usa la funzione read.table(),<br />
che automaticamente controlla se le variabili sono quantitative o qualitative e se le<br />
righe/colonne hanno etichette. Si supponga che nella <strong>di</strong>rectory <strong>di</strong> lavoro si trovi il<br />
file, <strong>di</strong> nome cherry.dat, così costituito:<br />
8.3 70 10.3<br />
8.6 65 10.3<br />
8.8 63 10.2<br />
10.5 72 16.4<br />
10.7 81 18.8<br />
10.8 83 19.7<br />
...<br />
...<br />
Si noti, <strong>in</strong> particolare, che il file non contiene alcuna <strong>in</strong>testazione, ovvero non è<br />
specificato alcun nome per le righe e le colonne del file. Si può acquisire il contenuto<br />
del file e assegnarlo ad un data frame me<strong>di</strong>ante il comando:<br />
> Ciliegi