The best thing about R is that it was developed by statisticians. The worst thing about R is that … it was developed by statisticians
¿Que es? Un software libre para computación estadÃstica y gráficos con cerca de 30 años
¿Por qué? Un software libre para computación estadÃstica y gráficos
¿Lo bueno? Un lenguaje simple. Miles de paquetes desarrollados por la comunidad. Academia.
¿Lo meh? No es lo más rápido. No posee la mejor escalabildiad
¿A Que se parece? A otros lenguajes de programción como python.
¿Descargas? Software: https://www.r-project.org/. Interfaz (IDE): https://www.rstudio.com/
"hello"
## [1] "hello"
1 + 3
## [1] 4
vector <- c(3, 4, 5)
sum(vector)
## [1] 12
barplot(c(1, 3, 2), main = "Mi primer gráfico :D")
library("highcharter")
library("rgexf")
library("stringr")
library("purrr")
library("resolution")
library("readr")
net <- "http://media.moviegalaxies.com/gexf/316.gexf" %>%
read_lines() %>%
read.gexf() %>%
gexf.to.igraph()
V(net)$name <- str_to_title(V(net)$name)
V(net)$label <- V(net)$name %>%
str_extract_all("^\\w{2}| \\w") %>%
map_chr(function(x) {
x %>% unlist() %>% str_c(collapse = "")
})
V(net)$size <- degree(net)^2 # page.rank(net)$vector
V(net)$degree <- degree(net)
cl <- cluster_resolution(net)
V(net)$comm <- membership(cl)
V(net)$color <- colorize_vector(V(net)$comm)
hc <- hchart(net, minSize = 10, maxSize = 20)
hc
Esta presentación
Aplicaciones web:
# esto es un comentario
# numericas
4
## [1] 4
# asignacion
a <- 5
a
## [1] 5
# carácter
"esto es un 'string'"
## [1] "esto es un 'string'"
# listas
l <- list(elemento1 = c(2, 3), el2 = "otro elemento")
# accesar a elementos
l$elemento1
## [1] 2 3
l[["el2"]]
## [1] "otro elemento"
library("readr") # para lectura de datos
library("dplyr") # para manipulacion
data <- read_csv("http://jkunst.com/data/german_credit.csv")
dim(data)
## [1] 49694 17
names(data)
## [1] "id_client" "sex" "marital_status"
## [4] "age" "flag_res_phone" "area_code_res_phone"
## [7] "payment_day" "residence_type" "months_in_residence"
## [10] "months_in_the_job" "profession_code" "flag_other_card"
## [13] "flag_mobile_phone" "flag_contact_phone" "personal_net_income"
## [16] "quant_add_cards" "bad"
# podemos accesar a las columnas al igual como en listas.
# head muestra los primeros elementos de un objecto
head(data$age)
## [1] 44 22 27 32 36 46
# asignacion
edades <- data$age
summary(edades)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 15.00 23.00 33.00 34.68 43.00 95.00
# selectionar
select(data, age, bad)
## Source: local data frame [49,694 x 2]
##
## age bad
## (int) (int)
## 1 44 0
## 2 22 0
## 3 27 1
## 4 32 0
## 5 36 0
## 6 46 0
## 7 17 1
## 8 20 1
## 9 71 0
## 10 46 0
## .. ... ...
# filtrar
filter(data, age == 20)
## Source: local data frame [2,531 x 17]
##
## id_client sex marital_status age flag_res_phone area_code_res_phone
## (int) (chr) (chr) (int) (chr) (int)
## 1 26 M S 20 Y 50
## 2 91 M S 20 Y 50
## 3 183 M S 20 Y 1
## 4 199 F S 20 Y 31
## 5 220 M S 20 Y 31
## 6 332 F C 20 Y 31
## 7 334 F C 20 N 50
## 8 362 F O 20 N 50
## 9 402 F S 20 Y 31
## 10 416 M S 20 N 50
## .. ... ... ... ... ... ...
## Variables not shown: payment_day (int), residence_type (chr),
## months_in_residence (int), months_in_the_job (int), profession_code
## (int), flag_other_card (chr), flag_mobile_phone (chr),
## flag_contact_phone (chr), personal_net_income (dbl), quant_add_cards
## (int), bad (int)