forked from joanby/r-basic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
79 changed files
with
1,488 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"cells": [], | ||
"metadata": {}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Entrada y salida de datos" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Hola, me llamo Juan Gabriel\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(\"Hola, me llamo Juan Gabriel\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"5\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"x = 5\n", | ||
"print(x)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"El valor de la variable x es: 5\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(\"El valor de la variable x es: \"+str(x))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"texto = input(\"Introduce aquí tu nombre: \")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.5.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
base |
Binary file added
BIN
+2.83 KB
...pts/tema12/01-diamonds_cache/html/unnamed-chunk-10_4779ac4a62c84c0a676202a8ae084b0e.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-10_4779ac4a62c84c0a676202a8ae084b0e.rdx
Binary file not shown.
Binary file added
BIN
+3.42 KB
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-1_096a7a0b64254b3c70c246e7568ba470.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-1_096a7a0b64254b3c70c246e7568ba470.rdx
Binary file not shown.
Binary file added
BIN
+2.8 KB
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-2_93ece90322530318e6fe2ea6e420dc8b.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-2_93ece90322530318e6fe2ea6e420dc8b.rdx
Binary file not shown.
Binary file added
BIN
+3.07 KB
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-3_19ca6f580f71f07011bd9c45bc6c70b8.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-3_19ca6f580f71f07011bd9c45bc6c70b8.rdx
Binary file not shown.
Binary file added
BIN
+2.77 KB
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-4_477b9ef6be9ba8dab22a82595eed5e31.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-4_477b9ef6be9ba8dab22a82595eed5e31.rdx
Binary file not shown.
Binary file added
BIN
+2.78 KB
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-5_b721f9d48526f5fde3e9cddbf339d025.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-5_b721f9d48526f5fde3e9cddbf339d025.rdx
Binary file not shown.
Binary file added
BIN
+2.78 KB
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-6_ad2fdaad3a00602260ce4b0dc5c7df5a.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-6_ad2fdaad3a00602260ce4b0dc5c7df5a.rdx
Binary file not shown.
Binary file added
BIN
+2.79 KB
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-7_8ad9c425595259b3c344215090e0ca6d.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-7_8ad9c425595259b3c344215090e0ca6d.rdx
Binary file not shown.
Binary file added
BIN
+2.93 KB
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-8_41f1b40282d4e05a41fedf2e23619116.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-8_41f1b40282d4e05a41fedf2e23619116.rdx
Binary file not shown.
Binary file added
BIN
+3.14 KB
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-9_4c8906161007bde0450d5b26c7dbe3d0.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/01-diamonds_cache/html/unnamed-chunk-9_4c8906161007bde0450d5b26c7dbe3d0.rdx
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
title: "Pokemon" | ||
author: "Curso de Estadística Descriptiva" | ||
date: "9/1/2019" | ||
output: html_document | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = TRUE, cache = TRUE) | ||
library(reticulate) | ||
use_python("/anaconda3/bin/python") | ||
``` | ||
|
||
# Pokemon (Py -> R) | ||
|
||
## Limpieza de datos en Python | ||
|
||
```{python} | ||
import pandas as pd | ||
pokemon = pd.read_csv("../../data/Pokemon.csv") | ||
print(pokemon.head()) | ||
print(pokemon.shape) | ||
pokemon = pokemon[pokemon["Generation"]==1] | ||
pokemon = pokemon[["Type 1", "Type 2", "Speed"]] | ||
print(pokemon.shape) | ||
pokemon = pokemon.dropna() | ||
print(pokemon.shape) | ||
``` | ||
|
||
## Transmisión de los datos de Python a R | ||
```{r, fig.width=7, fig.height=4} | ||
hist(py$pokemon[,"Speed"], breaks = 10, main = "Velocidad de los Pokemon") | ||
``` | ||
|
||
# Pokemon (R -> Py) | ||
## Carga de datos en R | ||
```{r} | ||
pokemon2 <- read.csv("../../data/Pokemon.csv", header = TRUE) | ||
head(pokemon2) | ||
library(tidyverse) | ||
pokemon2 <- pokemon2 %>% | ||
filter(Generation == 1) %>% | ||
select(Type.1, Type.2, Speed) %>% | ||
na.omit() | ||
summary(pokemon2) | ||
``` | ||
|
||
## Transmisión de datos de R a Python | ||
```{python} | ||
print(r.pokemon2.head()) | ||
``` | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
base | ||
reticulate | ||
tidyverse | ||
ggplot2 | ||
tibble | ||
tidyr | ||
readr | ||
purrr | ||
dplyr | ||
stringr | ||
forcats | ||
bindrcpp |
Binary file added
BIN
+3.03 KB
scripts/tema12/02-pokemon_cache/html/unnamed-chunk-1_1c495cfb97f70130860b49921495a756.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/02-pokemon_cache/html/unnamed-chunk-1_1c495cfb97f70130860b49921495a756.rdx
Binary file not shown.
Binary file added
BIN
+2.78 KB
scripts/tema12/02-pokemon_cache/html/unnamed-chunk-2_f690a6a77dff8b57800e18e0f8d4a9ea.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/02-pokemon_cache/html/unnamed-chunk-2_f690a6a77dff8b57800e18e0f8d4a9ea.rdx
Binary file not shown.
Binary file added
BIN
+3.5 KB
scripts/tema12/02-pokemon_cache/html/unnamed-chunk-3_e31fdf903d1dac6c7594287cf69878c6.RData
Binary file not shown.
Binary file added
BIN
+705 Bytes
scripts/tema12/02-pokemon_cache/html/unnamed-chunk-3_e31fdf903d1dac6c7594287cf69878c6.rdb
Binary file not shown.
Binary file added
BIN
+138 Bytes
scripts/tema12/02-pokemon_cache/html/unnamed-chunk-3_e31fdf903d1dac6c7594287cf69878c6.rdx
Binary file not shown.
Binary file added
BIN
+2.77 KB
scripts/tema12/02-pokemon_cache/html/unnamed-chunk-4_c752c7d5520433c63985be7e17c14657.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/02-pokemon_cache/html/unnamed-chunk-4_c752c7d5520433c63985be7e17c14657.rdx
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: "Vuelos de NYC" | ||
author: "Curso de Estadística Descriptiva" | ||
date: "9/1/2019" | ||
output: html_document | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = TRUE) | ||
library(reticulate) | ||
``` | ||
|
||
## Vuelos de NYC | ||
|
||
```{r} | ||
data <- nycflights13::flights | ||
head(data) | ||
nrow(data) | ||
summary(data) | ||
``` | ||
|
||
```{python} | ||
pydata = r.data | ||
pydata = pydata[pydata["dest"]=="ORD"] | ||
pydata = pydata[['carrier', 'dep_delay', 'arr_delay', 'origin']] | ||
pydata = pydata[pydata['arr_delay']<6*60] | ||
pydata = pydata.dropna() | ||
print(pydata.head()) | ||
print(pydata.shape) | ||
``` | ||
|
||
```{r} | ||
summary(py$pydata) | ||
boxplot(arr_delay~origin, data = py$pydata, main = "Retraso de los vuelo hacia Orlando desde NYC") | ||
``` | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
title: "Coches" | ||
author: "Curso de Estadística Descriptiva" | ||
date: "9/1/2019" | ||
output: html_document | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = TRUE, cache = TRUE) | ||
``` | ||
|
||
## Análisis de los coches (mtcars) | ||
|
||
### Carga de datos | ||
```{python} | ||
from ggplot import mtcars | ||
data = mtcars | ||
data.index = data["name"] | ||
print(data.head()) | ||
``` | ||
|
||
### Medidas de centralización | ||
```{python} | ||
print(data.mean()) # Media por columnas | ||
print(data.mean(axis = 1)) # Media por filas | ||
print(data.median()) | ||
print(mtcars.mode()) | ||
``` | ||
|
||
|
||
### Medidas vs distribuciones | ||
```{python} | ||
import numpy as np | ||
import pandas as pd | ||
import matplotlib.pyplot as plt | ||
plt.clf() | ||
norm_data = pd.DataFrame(np.random.normal(size=100000)) | ||
norm_data.plot(kind="density", figsize=(10,10)) | ||
plt.vlines(norm_data.mean(), ymin = 0, ymax = 0.4, linewidth=5.0, color = "green") | ||
plt.vlines(norm_data.median(), ymin = 0, ymax = 0.4, | ||
linewidth = 2.0, color = "red") | ||
plt.show() | ||
plt.clf() | ||
skewed_data = pd.DataFrame(np.random.exponential(size=100000)) | ||
skewed_data.plot(kind="density", figsize=(10,10), xlim = (-1,5)) | ||
plt.vlines(skewed_data.mean(), ymin = 0, ymax = 1.0, linewidth=5.0, color = "green") | ||
plt.vlines(skewed_data.median(), ymin = 0, ymax = 1.0, | ||
linewidth = 2.0, color = "red") | ||
plt.show() | ||
norm_data = np.random.normal(size = 50) | ||
outliers = np.random.normal(15, size = 3) | ||
combined_data = pd.DataFrame(np.concatenate((norm_data, outliers), axis = 0)) | ||
combined_data.plot(kind="density", figsize=(10,10), xlim = (-5,20)) | ||
plt.vlines(combined_data.mean(), ymin = 0, ymax = 0.3, linewidth=5.0, color = "green") | ||
plt.vlines(combined_data.median(), ymin = 0, ymax = 0.3, | ||
linewidth = 2.0, color = "red") | ||
plt.show() | ||
``` | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
base |
Binary file added
BIN
+3.32 KB
scripts/tema12/04-mtcars_cache/html/unnamed-chunk-1_5aa8e92586c06f87372ee9224a714830.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/04-mtcars_cache/html/unnamed-chunk-1_5aa8e92586c06f87372ee9224a714830.rdx
Binary file not shown.
Binary file added
BIN
+4.02 KB
scripts/tema12/04-mtcars_cache/html/unnamed-chunk-2_79c3d81e9889d036bd7a43c4b2629709.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/04-mtcars_cache/html/unnamed-chunk-2_79c3d81e9889d036bd7a43c4b2629709.rdx
Binary file not shown.
Binary file added
BIN
+3.11 KB
scripts/tema12/04-mtcars_cache/html/unnamed-chunk-3_ca3b58f96a4c64b743f5686c7fcc0874.RData
Binary file not shown.
Empty file.
Binary file added
BIN
+113 Bytes
scripts/tema12/04-mtcars_cache/html/unnamed-chunk-3_ca3b58f96a4c64b743f5686c7fcc0874.rdx
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.