transfer: Transfer information between two dataframes.

Description Usage Arguments Details Value Author(s) Examples

View source: R/transfer.R

Description

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.

Usage

1
2
transfer(to, from, by, insert_missing = TRUE, order_to = TRUE,
  order_from = TRUE)

Arguments

to

Dataframe to transfer information to.

from

Dataframe to get information from.

by

Names of columns to match starting positions by.

Given as vector c("to", "from") or just "shared" if it's named the same in both dataframes. (Character)

E.g. by = c("time", "start_time")

insert_missing

If some starting positions are not found in the to dataframe: Insert them in new rows >> Order the dataframe by the by column >> Transfer the summary information >> Remove the inserted rows. (Logical)

order_to

Order the to dataframe by its by column first. (Logical)

order_from

Order the from dataframe by its by column first. (Logical)

Details

Starting positions are the values in the by column of the from dataframe.

Value

The to dataframe with the added columns from the from dataframe.

Author(s)

Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Attach packages
library(transfrr)
library(dplyr)

# Get data (Note: loaded with transfrr)
sunspots <- sunspots_
presidents <- USA.presidents

# Transfer the presidents' information
# to the time of their presidency
transferred <- sunspots %>%
  transfer(presidents, by = c("start_date", "took_office"))

# Note that the first rows will contain NAs, as they lie
# before the first US president. Check the tail for proof
# that it works.
tail(transferred)

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