Mi primer documento de Quarto


library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(fpp3)
── Attaching packages ────────────────────────────────────────────── fpp3 0.5 ──
✔ tsibble     1.1.3     ✔ fable       0.3.3
✔ tsibbledata 0.4.1     ✔ fabletools  0.3.4
✔ feasts      0.3.1     
── Conflicts ───────────────────────────────────────────────── fpp3_conflicts ──
✖ lubridate::date()    masks base::date()
✖ dplyr::filter()      masks stats::filter()
✖ tsibble::intersect() masks base::intersect()
✖ tsibble::interval()  masks lubridate::interval()
✖ dplyr::lag()         masks stats::lag()
✖ tsibble::setdiff()   masks base::setdiff()
✖ tsibble::union()     masks base::union()

Acciones

Las tsibbles son data frames (tibblespara series de tiempo). Tienen 2 argumentos característicos para series de tiempo:

  • index: Una columna que contiene a la variable temporal. En este caso es la columna Date.
  • key: No es obligatorio cuando solo tiene una serie de tiempo. Si la tabla contiene más de una serie de tiempo (en filas), si es obligatorio definir el key.
gafa_stock
gafa_stock
gafa_stock  |>  #pipe
  distinct(Symbol)
gafa_stock  |>
  #Pasar las columnas a filas 
  pivot_longer(cols = -c(Symbol, Date), names_to = "tipo", values_to = "valor") |> 
  #Convertir a tibble
  as_tibble() |> 
  # Agrupar por acción y tipo de var.
  group_by(Symbol, tipo) |>
  #Sacar la media por grupos
  summarise(media = mean(valor)) |>
  # Pasar los tipos de columnas
  pivot_wider(names_from = Symbol, values_from = media)
`summarise()` has grouped output by 'Symbol'. You can override using the
`.groups` argument.
gafa_stock |>
  autoplot(Close) +
  facet_wrap(~ Symbol, scales = "free_y") +
  theme(legend.position = "none") 

gafa_stock |>
  select(-Volume) |>
  pivot_longer(cols = -c(Symbol, Date), names_to = "tipo", values_to = "valor") |>
  autoplot(valor) + 
  facet_grid(Symbol ~ tipo, scales = "free") +
  theme(legend.position = "none")