knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

transfrr

R package: Add summary information from one dataframe to the dataframe that has been summarized, given only starting posititions of summarized groups.

E.g. used when one dataframe consists of timestamped samples and another contains summary information about blocks of time.

Imagine a sampled heart rate with columns 'time' and 'signal' in one dataframe and information about events that happened in blocks of the sampling, with start times of the blocks, in the other dataframe. See Examples.

By Ludvig R. Olsen,
Cognitive Science, Aarhus University.
Started in Oct. 2016

Contact at: r-pkgs@ludvigolsen.dk

Main functions:

Installation

Dependencies:

install.packages("devtools")

install.packages("groupdata2")

Development version:

devtools::install_github("LudvigOlsen/transfrr")

Examples

Attach Packages

library(transfrr)
library(dplyr)
library(knitr)
library(ggplot2)

Load data

sunspots <- sunspots_
presidents <- USA.presidents

sunspots %>% head(5) %>% kable()
presidents %>% head(5) %>% kable()

Transferring presidents to the months of their presidency

transferred <- sunspots %>% 
  transfer(presidents, by = c("start_date", "took_office"))
# Notice: The first rows will contain NAs
# as there was no US president at the time
transferred %>% head(5) %>% kable()
transferred %>% head(1000) %>% tail(5) %>% kable()
transferred %>% tail(5) %>% kable()
# Plotting sunspots per president
ggplot(transferred, aes(president, sunspots)) +
  geom_violin() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1))
# Plotting sunspots over time
ggplot(transferred, aes(start_date, sunspots)) +
  geom_point() +
  geom_smooth()


LudvigOlsen/transfrr documentation built on May 28, 2019, 1:34 p.m.