Errata / Additions

  • last time we looked at some packages from the tidyverse (https://www.tidyverse.org)

  • as noted above, magrittr provides the tidyverse pipe

  • this can be combined with dplyr for various data preparation/manipulation steps

    library(tidyverse)
    
    # create some toy data
    set.seed(123)
    dat <- data.frame(id = rep(1:4, each=5),
                      y  = sample(5:10, 4*5, replace=TRUE))
    dat
    
    # get the mean of every subject the tidyverse way
    dat %>%
       group_by(id) %>%
       summarise(meany = mean(y))
  • a lightweight alternative to dplyr and magrittr is provided by the poorman package (https://cran.r-project.org/package=poorman)

    # create some toy data
    set.seed(123)
    dat <- data.frame(id = rep(1:4, each=5),
                      y  = sample(5:10, 4*5, replace=TRUE))
    dat
    
    # install and load the poorman package
    #install.packages(poorman)
    library(poorman)
    
    # get the mean of every subject
    dat %>%
       group_by(id) %>%
       summarise(meany = mean(y))
  • and in the future, should be able to combine this with R’s native pipe

    dat |>
       group_by(id) |>
       summarise(meany = mean(y))