Creates a long dataset of "n" columns comprising the combinations of values from different columns.

lengthener(indt, n = 2)

Arguments

indt

The input dataset.

n

The number of columns expected. Passed on to combn.

Value

A data.table.

References

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

Author

Ananda Mahto

Examples

mydf <- as.data.frame(matrix(c(1,2,3,4,0,0,1,1), byrow = TRUE, nrow = 2)) lengthener(mydf, 2)
#> V1 V2 #> 1: 1 2 #> 2: 1 3 #> 3: 1 4 #> 4: 2 3 #> 5: 2 4 #> 6: 3 4 #> 7: 0 0 #> 8: 0 1 #> 9: 0 1 #> 10: 0 1 #> 11: 0 1 #> 12: 1 1
lengthener(mydf, 3)
#> V1 V2 V3 #> 1: 1 2 3 #> 2: 1 2 4 #> 3: 1 3 4 #> 4: 2 3 4 #> 5: 0 0 1 #> 6: 0 0 1 #> 7: 0 1 1 #> 8: 0 1 1