Learn R Programming

turner (version 0.1.9)

df_to_blocks: Split a data frame into blocks

Description

Split a data frame into a list of blocks (either by rows or by columns)

Usage

df_to_blocks(DataFrame, blocks, byrow = TRUE)

Value

A list of data frames

Arguments

DataFrame

a data frame to split

blocks

either a list or a vector indicating the blocks. If blocks is a list of vectors, then the length of each vector defines the size of the blocks. If blocks is a vector, then each element represents the size of the blocks.

byrow

logical. If TRUE (the default) the data frame is split by rows, otherwise the data frame is split by columns

Author

Gaston Sanchez

See Also

matrix_to_blocks

Examples

Run this code
# say you have a data frame
iris_df = iris[c(1:3,51:53,101:103),]

# list defining the blocks
row_blocks = list(1:3, 4:6, 7:9)
col_blocks = c(2, 2, 1)

# split data into list of blocks (by rows)
df_to_blocks(iris_df, row_blocks)

# split data into list of blocks (by columns)
df_to_blocks(iris_df, col_blocks, byrow=FALSE)

Run the code above in your browser using DataLab