Coder Social home page Coder Social logo

transfrr's Introduction

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: [email protected]

Main functions:

  • transfer

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()
sunspots year month start_date
58.0 1749 1 1749-01-01
62.6 1749 2 1749-02-01
70.0 1749 3 1749-03-01
55.7 1749 4 1749-04-01
85.0 1749 5 1749-05-01
presidents %>% head(5) %>% kable()
presidency president took_office party home_state
1 George Washington 1789-04-30 Independent Virginia
2 John Adams 1797-03-04 Federalist Massachusetts
3 Thomas Jefferson 1801-03-04 Democratic-Republican Virginia
4 James Madison 1809-03-04 Democratic-Republican Virginia
5 James Monroe 1817-03-04 Democratic-Republican Virginia

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()
sunspots year month start_date presidency president took_office party home_state
58.0 1749 1 1749-01-01 NA NA NA NA NA
62.6 1749 2 1749-02-01 NA NA NA NA NA
70.0 1749 3 1749-03-01 NA NA NA NA NA
55.7 1749 4 1749-04-01 NA NA NA NA NA
85.0 1749 5 1749-05-01 NA NA NA NA NA
transferred %>% head(1000) %>% tail(5) %>% kable()
sunspots year month start_date presidency president took_office party home_state
28.9 1831 12 1831-12-01 7 Andrew Jackson 1829-03-04 Democratic Tennessee
30.9 1832 1 1832-01-01 7 Andrew Jackson 1829-03-04 Democratic Tennessee
55.6 1832 2 1832-02-01 7 Andrew Jackson 1829-03-04 Democratic Tennessee
55.1 1832 3 1832-03-01 7 Andrew Jackson 1829-03-04 Democratic Tennessee
26.9 1832 4 1832-04-01 7 Andrew Jackson 1829-03-04 Democratic Tennessee
transferred %>% tail(5) %>% kable()
sunspots year month start_date presidency president took_office party home_state
63.0 2012 8 2012-08-01 44 Barack Obama 2009-01-20 Democratic Illinois
61.4 2012 9 2012-09-01 44 Barack Obama 2009-01-20 Democratic Illinois
53.3 2012 10 2012-10-01 44 Barack Obama 2009-01-20 Democratic Illinois
61.8 2012 11 2012-11-01 44 Barack Obama 2009-01-20 Democratic Illinois
40.8 2012 12 2012-12-01 44 Barack Obama 2009-01-20 Democratic Illinois
# 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()
#> `geom_smooth()` using method = 'gam'

transfrr's People

Contributors

ludvigolsen avatar

Stargazers

Andrew Allen Bruce avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.