Simple frequency tables using data.table

前端 未结 1 1892
遇见更好的自我
遇见更好的自我 2020-12-08 02:44

I\'m looking for a way to do simple aggregates / counts via data.table.

Consider the iris data, which has 50 observations per species. To count the observations per

1条回答
  •  渐次进展
    2020-12-08 03:03

    data.table has a couple of symbols that can be used within the j expression. Notably

    • .N will give you the number of number of rows in each group.

    see ?data.table under the details for by

    Advanced: When grouping by by or by i, symbols .SD, .BY and .N may be used in the j expression, defined as follows.

    ....

    .N is an integer, length 1, containing the number of rows in the group.

    For example:

    dt[, .N ,by = Species]
    
         Species  N
    1:     setosa 50
    2: versicolor 50
    3:  virginica 50
    

    0 讨论(0)
提交回复
热议问题