collapse_df: Collapse a dataframe into a vector

View source: R/dataframe_tools.R

collapse_dfR Documentation

Collapse a dataframe into a vector

Description

Useful for taking every number in a table and plotting it in a histogram, for example.

Usage

collapse_df(df, from = 1, to = NULL, cols = NULL)

Arguments

df

(Dataframe) A dataframe.

from, to

(Numeric or NULL) The start and end of a continuous range of columns that will be considered for the empty/not-empty decision. For example, columns that are always filled should be omitted (see examples). If to is NULL, it defaults to the last column in df so that ⁠from = 2, to = NULL⁠ is the same as 2:length(df).

cols

(Numeric or NULL) A numeric vector of the columns to consider. This allows you to select non-contiguous columns. If the cols argument is being used (not-NULL), from and to will be ignored.

Value

A vector containing the cell contents from the selected columns of df. If all of the cells are numeric, the vector is Numeric. If any of the cells contain strings, the vector is Character. The columns are concatenated in order.

Authors

Examples

collapse_df(iris, cols = 1:4)

#> [1] 5.1 4.9 4.7 4.6 5.0 5.4 4.6 5.0 4.4 4.9 5.4 4.8 ...


DesiQuintans/desiderata documentation built on April 9, 2023, 5:43 a.m.