concept data.table in category R

appears as: data.table, data.tables
Practical Data Science with R, Second Edition

This is an excerpt from Manning's book Practical Data Science with R, Second Edition.

Identifiers or symbol names are how R refers to variables and functions. The Google R Style Guide insists on writing symbol names in what is called “CamelCase” (word boundaries in names are denoted by uppercase letters, as in “CamelCase” itself). The Advanced R guide recommends an underscore style where names inside identifiers are broken up with underscores (such as “day_one” instead of “DayOne”). Also, many R users use a dot to break up names with identifiers (such as “day.one”). In particular, important built-in R types such as data.frame and packages such as data.table use the dot notation convention.

  • data.table— data.table is the package for fast and memory-efficient data manipulation in R. It differs from normal R semantics in that data.table uses reference semantics where changes are made directly in a shared data structure (visible to all references to the same structure) instead of R’s more typical value semantics (where changes made in one reference do not become visible to other references). data.table notation specifies powerful transforms through a variation of the []-indexing operator, and is well explained in help(data .table, package="data.table") and vignette("datatable-intro", package= "data.table").
  • dplyr— dplyr is a popular data manipulation package that emphasizes data manipulations through sequences of SQL-like (or Codd-style) operators. dplyr is usually not as fast (or space efficient) as data.table, but the notations are convenient.
  • Row and column selection in data.table is performed similarly to base R. data .table uses a very powerful set of index notations. In this case, we use a .. notation to tell data.table that we are using the second index position to specify column names (and not to specify calculations, as we will demonstrate later).

    library("data.table")
    
    iris_data.table <- as.data.table(iris)                                 #1
    
    columns_we_want <- c("Petal.Length", "Petal.Width", "Species")
    rows_we_want <- iris_data.table$Petal.Length > 2
    
    iris_data.table <- iris_data.table[rows_we_want , ..columns_we_want]   #2
    
    head(iris_data.table)
    
    ##    Petal.Length Petal.Width    Species
    ## 1:          4.7         1.4 versicolor
    ## 2:          4.5         1.5 versicolor
    ## 3:          4.9         1.5 versicolor
    ## 4:          4.0         1.3 versicolor
    ## 5:          4.6         1.5 versicolor
    ## 6:          4.5         1.3 versicolor

    The advantage of data.table is that it is the fastest and most memory efficient solution for data wrangling in R at a wide range of scales. data.table has a very helpful FAQ, and there is a nice cheat sheet: