add_id just ensures data is a data.table and adds a columns named .id

add_id(data)

Arguments

data

Source data (data.frame or data.table)

Value

data.table object with a column named .id

Details

add_id in called behing the scence by crazyfy if needed to ensure a valid id is present in source data. Still, we recommand to start from a dataset already having an id, be it generated by a call to add_id or already pre-existing to ensure correct source data enrichment.

Examples

library(stranger)
data(iris)
(iris.id <- add_id(iris))
#>      Sepal.Length Sepal.Width Petal.Length Petal.Width   Species .id
#>   1:          5.1         3.5          1.4         0.2    setosa   1
#>   2:          4.9         3.0          1.4         0.2    setosa   2
#>   3:          4.7         3.2          1.3         0.2    setosa   3
#>   4:          4.6         3.1          1.5         0.2    setosa   4
#>   5:          5.0         3.6          1.4         0.2    setosa   5
#>  ---                                                                
#> 146:          6.7         3.0          5.2         2.3 virginica 146
#> 147:          6.3         2.5          5.0         1.9 virginica 147
#> 148:          6.5         3.0          5.2         2.0 virginica 148
#> 149:          6.2         3.4          5.4         2.3 virginica 149
#> 150:          5.9         3.0          5.1         1.8 virginica 150