Datos existentes

Utilizamos los siguientes datos existentes.
Al ejecutar con el signo de interrogación delante, se representa la explicación en la zona de Help.
La tecla de atajo de ejecución es [Ctrl]+[Enter].

?iris #Edgar Anderson’s Iris Data
?caith #Colours of Eyes and Hair of People in Caithness
?HairEyeColor #Hair and Eye Color of Statistics Students
?mtcars #Motor Trend Car Road Tests
?USArrests #Violent Crime Rates by US State
?decathlon2 #Athletes’ performance in decathlon ?Titanic #Survival of passengers on the Titanic
?diamonds #Prices of over 50,000 round cut diamonds

Presentación de datos

Dt(iris) #Class: data.frame / Rows: 150 / Columns: 5
## Class: data.frame / Rows: 150 / Columns: 5
##  
##    Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1  5.1          3.5         1.4          0.2         setosa 
## 2  4.9          3.0         1.4          0.2         setosa 
## 3  4.7          3.2         1.3          0.2         setosa 
## 4  4.6          3.1         1.5          0.2         setosa 
## 5  5.0          3.6         1.4          0.2         setosa 
## 6  5.4          3.9         1.7          0.4         setosa 
## 7  4.6          3.4         1.4          0.3         setosa 
## 8  5.0          3.4         1.5          0.2         setosa 
## 9  4.4          2.9         1.4          0.2         setosa 
## 10 4.9          3.1         1.5          0.1         setosa
Dt(caith) #Class: data.frame / Rows: 4 / Columns: 5
## Class: data.frame / Rows: 4 / Columns: 5
##  
##        fair red medium dark black
## blue   326   38 241    110   3   
## light  688  116 584    188   4   
## medium 343   84 909    412  26   
## dark    98   48 403    681  85
Dt(HairEyeColor) #Class: table / Rows: 4 / Columns: 4
## Class: table / Rows: 4 / Columns: 4
##  
##    Hair  Eye   Sex  Freq
## 1  Black Brown Male 32  
## 2  Brown Brown Male 53  
## 3  Red   Brown Male 10  
## 4  Blond Brown Male  3  
## 5  Black Blue  Male 11  
## 6  Brown Blue  Male 50  
## 7  Red   Blue  Male 10  
## 8  Blond Blue  Male 30  
## 9  Black Hazel Male 10  
## 10 Brown Hazel Male 25
Dt(mtcars) #Class: data.frame / Rows: 32 / Columns: 11
## Class: data.frame / Rows: 32 / Columns: 11
##  
##                   mpg  cyl disp  hp  drat wt    qsec  vs am gear carb
## Mazda RX4         21.0 6   160.0 110 3.90 2.620 16.46 0  1  4    4   
## Mazda RX4 Wag     21.0 6   160.0 110 3.90 2.875 17.02 0  1  4    4   
## Datsun 710        22.8 4   108.0  93 3.85 2.320 18.61 1  1  4    1   
## Hornet 4 Drive    21.4 6   258.0 110 3.08 3.215 19.44 1  0  3    1   
## Hornet Sportabout 18.7 8   360.0 175 3.15 3.440 17.02 0  0  3    2   
## Valiant           18.1 6   225.0 105 2.76 3.460 20.22 1  0  3    1   
## Duster 360        14.3 8   360.0 245 3.21 3.570 15.84 0  0  3    4   
## Merc 240D         24.4 4   146.7  62 3.69 3.190 20.00 1  0  4    2   
## Merc 230          22.8 4   140.8  95 3.92 3.150 22.90 1  0  4    2   
## Merc 280          19.2 6   167.6 123 3.92 3.440 18.30 1  0  4    4
Dt(USArrests) #Class: data.frame / Rows: 50 / Columns: 4
## Class: data.frame / Rows: 50 / Columns: 4
##  
##             Murder Assault UrbanPop Rape
## Alabama     13.2   236     58       21.2
## Alaska      10.0   263     48       44.5
## Arizona      8.1   294     80       31.0
## Arkansas     8.8   190     50       19.5
## California   9.0   276     91       40.6
## Colorado     7.9   204     78       38.7
## Connecticut  3.3   110     77       11.1
## Delaware     5.9   238     72       15.8
## Florida     15.4   335     80       31.9
## Georgia     17.4   211     60       25.8
Dt(decathlon2) #Class: data.frame / Rows: 27 / Columns: 13
## Class: data.frame / Rows: 27 / Columns: 13
##  
##           X100m Long.jump Shot.put High.jump X400m X110m.hurdle Discus
## SEBRLE    11.04 7.58      14.83    2.07      49.81 14.69        43.75 
## CLAY      10.76 7.40      14.26    1.86      49.37 14.05        50.72 
## BERNARD   11.02 7.23      14.25    1.92      48.93 14.99        40.87 
## YURKOV    11.34 7.09      15.19    2.10      50.42 15.31        46.26 
## ZSIVOCZKY 11.13 7.30      13.48    2.01      48.62 14.17        45.67 
## McMULLEN  10.83 7.31      13.76    2.13      49.91 14.38        44.41 
## MARTINEAU 11.64 6.81      14.57    1.95      50.14 14.93        47.60 
## HERNU     11.37 7.56      14.41    1.86      51.10 15.06        44.99 
## BARRAS    11.33 6.97      14.09    1.95      49.48 14.48        42.10 
## NOOL      11.33 7.27      12.68    1.98      49.20 15.29        37.92 
##           Pole.vault Javeline X1500m Rank Points Competition
## SEBRLE    5.02       63.19    291.7   1   8217   Decastar   
## CLAY      4.92       60.15    301.5   2   8122   Decastar   
## BERNARD   5.32       62.77    280.1   4   8067   Decastar   
## YURKOV    4.72       63.44    276.4   5   8036   Decastar   
## ZSIVOCZKY 4.42       55.37    268.0   7   8004   Decastar   
## McMULLEN  4.42       56.37    285.1   8   7995   Decastar   
## MARTINEAU 4.92       52.33    262.1   9   7802   Decastar   
## HERNU     4.82       57.19    285.1  10   7733   Decastar   
## BARRAS    4.72       55.40    282.0  11   7708   Decastar   
## NOOL      4.62       57.44    266.6  12   7651   Decastar
Dt(Titanic) #Class: table / Rows: 4 / Columns: 2
## Class: table / Rows: 4 / Columns: 2
##  
##    Class Sex    Age   Survived Freq
## 1  1st   Male   Child No         0 
## 2  2nd   Male   Child No         0 
## 3  3rd   Male   Child No        35 
## 4  Crew  Male   Child No         0 
## 5  1st   Female Child No         0 
## 6  2nd   Female Child No         0 
## 7  3rd   Female Child No        17 
## 8  Crew  Female Child No         0 
## 9  1st   Male   Adult No       118 
## 10 2nd   Male   Adult No       154
Dt(diamonds) #Class: tbl_df, tbl, data.frame / Rows: 53940 / Columns: 10
## Class: tbl_df, tbl, data.frame / Rows: 53940 / Columns: 10
##  
##    carat cut       color clarity depth table price x    y    z   
## 1  0.23  Ideal     E     SI2     61.5  55    326   3.95 3.98 2.43
## 2  0.21  Premium   E     SI1     59.8  61    326   3.89 3.84 2.31
## 3  0.23  Good      E     VS1     56.9  65    327   4.05 4.07 2.31
## 4  0.29  Premium   I     VS2     62.4  58    334   4.20 4.23 2.63
## 5  0.31  Good      J     SI2     63.3  58    335   4.34 4.35 2.75
## 6  0.24  Very Good J     VVS2    62.8  57    336   3.94 3.96 2.48
## 7  0.24  Very Good I     VVS1    62.3  57    336   3.95 3.98 2.47
## 8  0.26  Very Good H     SI1     61.9  55    337   4.07 4.11 2.53
## 9  0.22  Fair      E     VS2     65.1  61    337   3.87 3.78 2.49
## 10 0.23  Very Good H     VS1     59.4  61    338   4.00 4.05 2.39

Selección de datos

Dt(E=D,r=10,c=0,n=F,rn=F,cn=F,d=’’)
D:Datos, r:número de filas,c:número de columnas,n:Mostrar rótulos de filas/columnas,rn:Mostrar rótulos de finas,cn:Mostrar rótulos de columnas,d:Mostrar el nombre de datos, etc.

D=Ip('x45.txt') #Ejemplo sencillo (Matriz numérica:4x5)
## File: x45.txt / Class: data.frame / Rows: 4 / Columns: 5
##  
##    A  B  C  D  E 
## w1 10 19 14  7 12
## w2 11  7 10  0  1
## w3  0  0  1 12  1
## w4  0  1  2  3  3
Dt(r=3) #Mostrar los datos (3 filas)
## Class: data.frame / Rows: 4 / Columns: 5
##  
##    A  B  C  D  E 
## w1 10 19 14  7 12
## w2 11  7 10  0  1
## w3  0  0  1 12  1
Dt(c=3) #Mostrar los datos (3 columnas)
## Class: data.frame / Rows: 4 / Columns: 5
##  
##    A  B  C 
## w1 10 19 14
## w2 11  7 10
## w3  0  0  1
## w4  0  1  2
Dt(r=3,c=3) #Mostrar los datos (3 filas: 3 columnas)
## Class: data.frame / Rows: 4 / Columns: 5
##  
##    A  B  C 
## w1 10 19 14
## w2 11  7 10
## w3  0  0  1
Dt(r=3,c=3,n=T) #Id+(n: Rótulos de filas/columnas)
## Class: data.frame / Rows: 4 / Columns: 5
##  
##    A  B  C 
## w1 10 19 14
## w2 11  7 10
## w3  0  0  1
## 
## Row names: 1.w1 2.w2 3.w3
##  
## Column names: 1.A 2.B 3.C
Dt(r=3,c=3,rn=T) #Id+(n: Rótulos de filas)
## Class: data.frame / Rows: 4 / Columns: 5
##  
##    A  B  C 
## w1 10 19 14
## w2 11  7 10
## w3  0  0  1
## 
## Row names: 1.w1 2.w2 3.w3
Dt(r=3,c=3,cn=T) #Id+(n: Rótulos de columnas)
## Class: data.frame / Rows: 4 / Columns: 5
##  
##    A  B  C 
## w1 10 19 14
## w2 11  7 10
## w3  0  0  1
## 
## Column names: 1.A 2.B 3.C

Mostrar los datos en Source Pane

D=Ip('x45'); Vista() #Ejemplo sencillo (Matriz numérica)
## File: x45.txt / Class: data.frame / Rows: 4 / Columns: 5
##  
##    A  B  C  D  E 
## w1 10 19 14  7 12
## w2 11  7 10  0  1
## w3  0  0  1 12  1
## w4  0  1  2  3  3

Vista()

Vista(diamonds) #Matriz grande

Vista(diamonds)

Edición de datos

D=Ip('x45'); D=edit(D); Dt() #Leer x45.txt; editar D; mostar D
## File: x45.txt / Class: data.frame / Rows: 4 / Columns: 5
##  
##    A  B  C  D  E 
## w1 10 19 14  7 12
## w2 11  7 10  0  1
## w3  0  0  1 12  1
## w4  0  1  2  3  3
## Class: data.frame / Rows: 4 / Columns: 5
##  
##    A  B  C  D  E 
## w1 10 19 14  7 12
## w2 11  7 10  0  1
## w3  0  0  1 12  1
## w4  0  1  2  3  3

edit()

D=Edit() #Editar D (por defecto)
X=Edit(diamonds) #Editar matriz grande 

Edit(diamonds)

Edición de fichero

Editamos un fichero dentro de Source Pane de RStudio.

File('dle') #Editar y guardar el fichero en Source Pane

File(‘dle’)

—–

Referencia

Portada

(Hiroto Ueda, Universidad de Tokio, 2022)