Unlists the values in a rectangular dataset (like a matrix, data.frame, or data.table) by row.

unlist_by_row(indt, source = TRUE)

unlist_by_col(indt, source = TRUE)

Arguments

indt

The input dataset.

source

Logical. Should columns indicating the original row and column positions be returned. Defaults to TRUE.

Value

A data.table if source = TRUE or a vector.

References

http://stackoverflow.com/q/36073947/1270695

Author

Ananda Mahto

Examples

unlist_by_row(mtcars)
#> row col value #> 1: 1 1 21.0 #> 2: 1 2 6.0 #> 3: 1 3 160.0 #> 4: 1 4 110.0 #> 5: 1 5 3.9 #> --- #> 348: 32 7 18.6 #> 349: 32 8 1.0 #> 350: 32 9 1.0 #> 351: 32 10 4.0 #> 352: 32 11 2.0
unlist_by_col(mtcars)
#> row col value #> 1: 1 1 21.0 #> 2: 2 1 21.0 #> 3: 3 1 22.8 #> 4: 4 1 21.4 #> 5: 5 1 18.7 #> --- #> 348: 28 11 2.0 #> 349: 29 11 4.0 #> 350: 30 11 6.0 #> 351: 31 11 8.0 #> 352: 32 11 2.0