data.table (version 1.10.4-2)

transpose: Efficient transpose of list

Description

transpose is an efficient way to transpose lists, data frames or data tables.

Usage

transpose(l, fill=NA, ignore.empty=FALSE)

Arguments

l

A list, data.frame or data.table.

fill

Default is NA. It is used to fill shorter list elements so as to return each element of the transposed result of equal lengths.

ignore.empty

Default is FALSE. TRUE will ignore length-0 list elements.

Value

A transposed list, data.frame or data.table.

Details

The list elements (or columns of data.frame/data.table) should be all atomic. If list elements are of unequal lengths, the value provided in fill will be used so that the resulting list always has all elements of identical lengths. The class of input object is also preserved in the transposed result.

The ignore.empty argument can be used to skip or include length-0 elements.

This is particularly useful in tasks that require splitting a character column and assigning each part to a separate column. This operation is quite common enough that a function tstrsplit is exported.

factor columns are converted to character type. Attributes are not preserved at the moment. This may change in the future.

See Also

data.table, tstrsplit

Examples

Run this code
# NOT RUN {
ll = list(1:5, 6:8)
transpose(ll)
setDT(transpose(ll, fill=0))[]

dt = data.table(x=1:5, y=6:10)
transpose(dt)
# }

Run the code above in your browser using DataCamp Workspace