head(select(mtcars, 1:3))
?select_helpers
head(select(mtcars, starts_with(“d”)))
head(select(mtcars, ends_with(“p”)))
head(select(mtcars, -drat, -am))
head(select(mtcars, contains(“a”)))
head(filter(mtcars, mpg > 20, gear == 4))
head(filter(mtcars, am == 1 & cyl <= 6))
head(filter(mtcars, mpg < 21 | carb < 3 & gear < 4))
mtcars_ordered <- mtcars[order(mtcars$cyl),] mtcars_ordered
mtcars_ordered1 <- mtcars[order(mtcars$disp),] mtcars_ordered1
mtcars\(ps <- round(mtcars\)wt * 0.45, 4) mtcars$ps round
View(mtcars)
media_disp <- summarise(mtcars, media_disp = mean(disp)) media_disp
summarise(group_by(mtcars, cyl), max = max(disp))
mtcars %>% select(mpg:disp) %>% head
head(select(select(mtcars, contains(“a”)), -drat, -am))
mtcars %>% select(contains(“a”), -drat, -am)
mtcars_filtered <- filter(mtcars, wt > 1.5) mtcars_grouped <- group_by(mtcars_filtered, cyl) summarise(mtcars_grouped, mn = mean(mpg), sd = sd(mpg)) print(“Se obtiene la media y la desviación estándar de la columna mpg, agrupadas según su cilindraje y siempre y cuando su wt sea mayor a 1.5.”)
mtcars %>% filter(wt > 1.5) %>% group_by(cyl) %>% summarise(mean(mpg), sd(mpg))
print(“Es obligatorio utilizar las funciones del paquete dplyr y
recomendable utilizar pipes %>% para los siguientes
ejercicios.”)
vuelosvuelos <- read.csv(“C:\Users\kevin\Downloads\vuelos.csv”) head(vuelos)
SFO u
OAK utilizando las funciones del paquete dplyr. ¿Con
cuántos vuelos nos quedamos?destinos <- vuelos %>% select(dest) %>% filter(dest %in% c(“SFO”, “OAK”)) %>% count() head(destinos) print(“Nos quedamos con un total de 1121 vuelos con destino a SFO y OAK.”)
retrasos <- vuelos %>% select(dest, arr_delay) %>% filter(arr_delay > 60) atrasos_por_destino <- table(retrasos$dest) atrasos_por_destino_ord <- sort(atrasos_por_destino, decreasing = TRUE) head(atrasos_por_destino_ord, 1) print(“El destino con mayores retrasos en proporción a los vuelos es Atlanta con un total de 23225 minutos de retrasos.”)
select para seleccionar las variables relacionadas con los
retrasos (delay)head(select(vuelos, contains(“delay”))) head(select(vuelos, ends_with(“delay”))) head(select(vuelos, matches(“.y”))) head(select(vuelos, dep_delay, arr_delay))
agfecha <- vuelos %>% select(date, hour, arr_delay) %>% group_by(date) %>% summarise(media = mean(arr_delay, na.rm = TRUE), mediana = median(arr_delay, na.rm = TRUE), cuartil_75 = quantile(arr_delay, 0.75, na.rm = TRUE)) head(agfecha)
cvuelos <- vuelos %>% select(date, hour, arr_delay, flight) %>% filter(flight > 10) %>% group_by(date) %>% summarise(media_retraso = mean(arr_delay, na
library("RODBC")
## Warning: package 'RODBC' was built under R version 4.3.2
conexvuelos <- odbcConnect(“ALEXACONX”, uid = “root”, pwd = “ALEXA@0499”)
vuelos1 <- sqlQuery(conexvuelos, “SELECT * FROM
gaby.vuelos t10”)
head(vuelos1)