easysplit: Quick and Efficient Data Splitting

Description Usage Arguments Value Note Examples

View source: R/easysplit.R

Description

easysplit is a function that efficiently splits a data.table, vector, or matrix based on criteria given by the user into multiple datasets within a list.

Usage

1
easysplit(x = NULL, ll = NULL)

Arguments

x

A data.table, matrix, or vector to split into list elements

ll

A list of named vectors where the vector names correspond to named elements of x and such that the values dictate the groups to split "x" by. where the values The elements of "ll" could be vectors of length greater than or equal to 1. See examples below.

Value

A list with one or more elements that are of the same class as "x" but have been split on values in "ll"

Note

The number of elements in "ll" and the size of those elements determines the number of elements in the return value.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(data.table)

dt <- data.table(ColA = c(1, 2, 3, 4, 5, 4, 4, 3, 3),
                 ColB = c("a", "b", "b", "c", "c", "c", "d", "e", "f"),
                 ColC = rnorm(9))

# Split the data by two values from ColA and one value from ColB.
# This will return a list of three data.tables
#
easysplit(x=dt, list(ColA = 3:4, ColB = "c"))

bfatemi/easydata documentation built on Oct. 7, 2019, 4:35 p.m.