Decidí realizar el proyecto final sobre Rmarkdown ya que este herramienta que nos permite realizar informes a partir de R. Y se puede incluir texto, imágenes, código (R, Python, SQL) y usar las fórmulas de Latex.
Adicionalmente nos permite poder publicarlo ya que permite que el formato de salida sea html5 de este modo podemos comprtir de manera facil un informe y que las demás personas puedan ver el código de nuestro proyecto, así como las explicaciones de esto muy facilmente.
A continución enseñaré como se realiza una asignación de variables en R:
### Asignar variables
139 +120
## [1] 259
x <- 139 +121
x
## [1] 260
y <- x/60
y
## [1] 4.333333
z = x/4
z
## [1] 65
Ahora para remover una variable en R podemos usar :
z <- 30
rm(z)
También podemos colocar matrices de Latex: \[ \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} \] Podemos usar Latex para cambiar el tamaño de fuente:
\(\Huge Hola!\) \(\huge Hola!\) \(\LARGE Hola!\) \(\Large Hola!\) \(\large Hola!\) \(\normalsize Hola!\) \(\small Hola!\) \(\scriptsize Hola!\) \(\tiny Hola!\)
library(readr)
datos <- read_csv("R/worldcities.csv")
## Rows: 44691 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (7): city, city_ascii, country, iso2, iso3, admin_name, capital
## dbl (4): lat, lng, population, id
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(datos)
## # A tibble: 6 × 11
## city city_ascii lat lng country iso2 iso3 admin_name capital population
## <chr> <chr> <dbl> <dbl> <chr> <chr> <chr> <chr> <chr> <dbl>
## 1 Tokyo Tokyo 35.7 140. Japan JP JPN Tōkyō primary 37732000
## 2 Jaka… Jakarta -6.18 107. Indone… ID IDN Jakarta primary 33756000
## 3 Delhi Delhi 28.6 77.2 India IN IND Delhi admin 32226000
## 4 Guan… Guangzhou 23.1 113. China CN CHN Guangdong admin 26940000
## 5 Mumb… Mumbai 19.1 72.9 India IN IND Mahārāsht… admin 24973000
## 6 Mani… Manila 14.6 121. Philip… PH PHL Manila primary 24922000
## # ℹ 1 more variable: id <dbl>
library(readr)
dt <- read_csv("R/healthcare-dataset-stroke-data.csv")
## Rows: 5110 Columns: 12
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (6): gender, ever_married, work_type, Residence_type, bmi, smoking_status
## dbl (6): id, age, hypertension, heart_disease, avg_glucose_level, stroke
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Esta tabla sacada de un data set de un proyecto que realicé con Google Colab
| stroke | smoking_status | Unknown | formerly smoked | never smoked smokes | All |
|---|---|---|---|---|---|
| 0 | 29.295499 | 15.949119 | 35.264188 | 14.618395 | 95.127202 |
| 1 | 0.919765 | 1.369863 | 1.761252 | 0.821918 | 4.872798 |
| All | 30.215264 | 17.318982 | 37.025440 | 15.440313 | 100.000000 |
gender <- as.factor(dt$gender)
stroke <- as.factor(dt$stroke)
Bar1 <- table(gender) # Tabla de frecuencias no agrupadas para Sexo
barplot(Bar1, # Se aplica barplot a esa tabla
main="Diagrama de barra", # Título principal
xlab="Genero", # Tíulo del eje X
ylab="Frecuencias", # Título del eje Y
col=c("pink","blue","green"), #H) Colorear las barras
)
Bar2<- table(gender, stroke)
barplot(Bar2,
main="Diagrama de barras",
xlab="Derrame Cerebral",
ylab="Frecuencias",
legend = rownames(Bar2),
col=c("pink","blue","green")
)