lapplydt: Apply function of subsets of 'data.frame', return named list

View source: R/lapplydt.R

lapplydtR Documentation

Apply function of subsets of 'data.frame', return named list

Description

Based on columns in data, run function on subsets of data and return the results in a list, carrying names of the subsets. Say a column is 'model' and you want to create a plot, run a regression or anything on the data for each model. In that case lapplydt(data,by="model",fun=function(x)lm(lAUC~lDose,data=x)). The l in lapplydt is because a list is returned (like lapply), the dt is because the input is a data.table.

Usage

lapplydt(data, by, fun, drop.null = FALSE)

Arguments

data

Data set to process. Must be a data.frame-like structure.

by

Column to split data by.

fun

function to pass to 'lapply()'.

drop.null

If some subsets return NULL, drop the empty elements in the returned list?

Details

the name of the current dataset can be reached with the '.nm' variable. like

Value

a list

Examples

pk <- readRDS(file=system.file("examples/data/xgxr2.rds",package="NMdata"))
lapplydt(pk,by="DOSE",fun=function(x) {
    message("this is subset",.nm)
    nrow(x) 
})

NMdata documentation built on Nov. 5, 2025, 5:43 p.m.