O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using symbols

We can use special symbols, such as .SD, .EACHI, .N, .I, and .BY in data.table, to enhance the functionality. We already saw some examples of .N, which represents the number of rows or the last row.

The .SD symbol holds all columns except the columns in by, and can be used only in the j evaluation part of data.table. The .SDcols symbol is used along with .SD and has columns to be included or excluded in the j part of data.table.

The .EACHI symbol is used in the by grouping to group each subset of the groups in i. This needs a key to be defined. If there is no key, R throws an error.

In the following example, we calculate the maximum salary in each department. If we omit .SDcols="Salary", then R will try to find the max for all ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required