I’d normally do this:
my.summary = function(x) list(mean = mean(x), median = median(x))
DT[, unlist(lapply(.SD, my.summary)), .SDcols = c('a', 'b')]
#a.mean a.median b.mean b.median
# 3 3 4 4
More Related Contents:
- data.table vs dplyr: can one do something well the other can’t or does poorly?
- How to delete a row by reference in data.table?
- Why does X[Y] join of data.tables not allow a full outer join, or a left join?
- dplyr mutate/replace several columns on a subset of rows
- Proper/fastest way to reshape a data.table
- Filtering out duplicated/non-unique rows in data.table
- data.table with two string columns of set elements, extract unique rows with each row unsorted
- Evaluating both column name and the target value within `j` expression within `data.table`
- Fill in missing values by group in data.table
- dplyr on data.table, am I really using data.table?
- data.table and parallel computing
- Elegantly assigning multiple columns in data.table with lapply()
- Sort a data.table fast by Ascending/Descending order
- No RTools compatible with R version 3.5.0 was found
- Join R data.tables where key values are not exactly equal–combine rows with closest times
- how to show a legend on dual y-axis ggplot
- Why is as.Date slow on a character vector?
- Cleaning `Inf` values from an R dataframe
- How to group data.table by multiple columns?
- can the value.var in dcast be a list or have multiple value variables?
- Apply a function to a subset of data.table columns, by column-indices instead of name
- Selecting a subset of columns in a data.table
- Merge overlapping ranges into unique groups, in dataframe
- add missing rows to a data table
- How to select R data.table rows based on substring match (a la SQL like)
- Any way to force fread() of data.table not to stop on empty lines?
- R data table: update join
- Split a string column into several dummy variables
- Is there a _fast_ way to run a rolling regression inside data.table?
- R fast single item lookup from list vs data.table vs hash