Speed Up Your Data Analysis with data.table

Gentle introduction

Author

DSA_406_001_SP25_wk4_cisrael

Today’s Lesson: Efficient Big Data Analysis with data.table

Objectives

  • Understand why data.table is crucial for big data analysis

  • Learn the syntax and key features of data.table

  • Practice with real-world Spotify data

  • Compare performance with traditional methods

Why data.table?

data.table is designed for handling large datasets (1GB to 100GB) with:

  • Lightning-fast operations

  • Memory efficiency

  • Concise syntax

  • Enhanced features for data manipulation

Setting Up

First, let’s install and load our required packages:

# Install and load required packages
required_packages <- c("data.table", "tidyverse", "microbenchmark", "pryr")

# Install missing packages
for (pkg in required_packages) {
  if (!requireNamespace(pkg, quietly = TRUE)) {
    install.packages(pkg)
  }
}

# Load libraries individually
#library(data.table)
#library(tidyverse)
#library(microbenchmark) # For precise timing
#library(pryr) # For memory tracking

#Load libraries
lapply(required_packages, library, character.only = TRUE)
[[1]]
[1] "data.table" "stats"      "graphics"   "grDevices"  "utils"     
[6] "datasets"   "methods"    "base"      

[[2]]
 [1] "lubridate"  "forcats"    "stringr"    "dplyr"      "purrr"     
 [6] "readr"      "tidyr"      "tibble"     "ggplot2"    "tidyverse" 
[11] "data.table" "stats"      "graphics"   "grDevices"  "utils"     
[16] "datasets"   "methods"    "base"      

[[3]]
 [1] "microbenchmark" "lubridate"      "forcats"        "stringr"       
 [5] "dplyr"          "purrr"          "readr"          "tidyr"         
 [9] "tibble"         "ggplot2"        "tidyverse"      "data.table"    
[13] "stats"          "graphics"       "grDevices"      "utils"         
[17] "datasets"       "methods"        "base"          

[[4]]
 [1] "pryr"           "microbenchmark" "lubridate"      "forcats"       
 [5] "stringr"        "dplyr"          "purrr"          "readr"         
 [9] "tidyr"          "tibble"         "ggplot2"        "tidyverse"     
[13] "data.table"     "stats"          "graphics"       "grDevices"     
[17] "utils"          "datasets"       "methods"        "base"          

Let’s read our Spotify data using data.table:

# Read the dataset using fread (much faster than read.csv() or read_csv())
#spotify_dt <- fread("https://docs.google.com/spreadsheets/d/e/2PACX-1vT9iNNoFknWSmgIglkiEXnmXkJplHHeEf9wPn07tvtOV-5eTh-MdYnLS3eyST_Bx2OXpd0GC9dw5gBt/pub?gid=1801845240&single=true&output=csv")

#read in teh data from data folder
spotify_dt <- fread("data/spotify_clean.csv")


spotify_csv <- read_csv("data/spotify_clean.csv")

Lets test it out with the fread function

# Let's measure memory usage
mem_before <- pryr::mem_used()
system.time(spotify_dt <- data.table::fread("data/spotify_clean.csv"))
   user  system elapsed 
   0.02    0.00    0.03 
mem_after_fread <- pryr::mem_used()
fread_memory <- mem_after_fread - mem_before

✅Now you try:

Now your turn try it out with the readr function read_csv

# Measure memory usage using read_csv
mem_before <- pryr::mem_used()
system.time(spotify_csv <- read_csv("data/spotify_clean.csv"))
Rows: 9999 Columns: 30
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (11): track_name, artist_name_s, album_name, album_artist_name_s, album...
dbl  (16): disc_number, track_number, track_duration_ms, popularity, danceab...
lgl   (2): explicit, album_genres
dttm  (1): added_at

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
   user  system elapsed 
   0.21    0.16    0.28 
mem_after_fread <- pryr::mem_used()
fread_memory <- mem_after_fread - mem_before

When you have an existing data frame (like one from tidyverse or base R like spotify_csv), you can convert it to a data.table using setDT().

# Option 1: setDT() - converts in place (memory efficient)
#setDT(spotify_csv)  # Converts the existing object to data.table

# Option 2: as.data.table() - creates a copy (uses more memory)
#spotify_dt <- as.data.table(spotify_csv)
  1. setDT() is more memory efficient because it modifies the existing object
  2. as.data.table() creates a copy, using twice the memory
  3. For big data, it’s best to read directly with fread() rather than converting
  4. The conversion only needs to happen if you start with a regular data frame

Here is a breakdown for comparison:

compare_methods <- function(file_path) {
 # Print initial memory state
 cat("Initial memory state:\n")
 print(gc())
 
 # Create container for results
 results <- list()
 
 # 1. fread method
 cat("\nTesting fread method...\n")
 mem_before <- pryr::mem_used()
 start_time <- Sys.time()
 dt1 <- data.table::fread(file_path)
 end_time <- Sys.time()
 mem_after <- pryr::mem_used()
 results$fread <- list(
   memory = (mem_after - mem_before) / 1024^2,  # Convert to MB
   time = end_time - start_time,
   size = format(object.size(dt1), units = "MB")
 )
 cat("fread object size:", results$fread$size, "\n")
 
 # 2. read_csv method
 cat("\nTesting read_csv method...\n")
 mem_before <- pryr::mem_used()
 start_time <- Sys.time()
 csv <- readr::read_csv(file_path)
 end_time <- Sys.time()
 mem_after <- pryr::mem_used()
 results$read_csv <- list(
   memory = (mem_after - mem_before) / 1024^2,
   time = end_time - start_time,
   size = format(object.size(csv), units = "MB")
 )
 cat("read_csv object size:", results$read_csv$size, "\n")
 
 # 3. setDT method
 cat("\nTesting setDT method...\n")
 mem_before <- pryr::mem_used()
 start_time <- Sys.time()
 csv_copy <- data.table::copy(csv)
 data.table::setDT(csv_copy)
 end_time <- Sys.time()
 mem_after <- pryr::mem_used()
 results$setDT <- list(
   memory = (mem_after - mem_before) / 1024^2,
   time = end_time - start_time,
   size = format(object.size(csv_copy), units = "MB")
 )
 cat("setDT object size:", results$setDT$size, "\n")
 
 # 4. as.data.table method
 cat("\nTesting as.data.table method...\n")
 mem_before <- pryr::mem_used()
 start_time <- Sys.time()
 dt2 <- data.table::as.data.table(csv)
 end_time <- Sys.time()
 mem_after <- pryr::mem_used()
 results$as_data_table <- list(
   memory = (mem_after - mem_before) / 1024^2,
   time = end_time - start_time,
   size = format(object.size(dt2), units = "MB")
 )
 cat("as.data.table object size:", results$as_data_table$size, "\n")
 
 # Final memory state
 cat("\nFinal memory state:\n")
 print(gc())
 
 # Create summary data.frame
 summary_df <- data.frame(
   method = names(results),
   memory_mb = sapply(results, function(x) round(x$memory, 2)),
   time_secs = sapply(results, function(x) round(as.numeric(x$time), 4)),
   final_size = sapply(results, function(x) x$size)
 )
 
 return(summary_df)
}

# Use the function
results <- compare_methods("data/spotify_clean.csv")
Initial memory state:
          used (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 1169281 62.5    2371894 126.7  2371894 126.7
Vcells 2969163 22.7    8388608  64.0  3641616  27.8

Testing fread method...
fread object size: 5.5 Mb 

Testing read_csv method...
Rows: 9999 Columns: 30
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (11): track_name, artist_name_s, album_name, album_artist_name_s, album...
dbl  (16): disc_number, track_number, track_duration_ms, popularity, danceab...
lgl   (2): explicit, album_genres
dttm  (1): added_at

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
read_csv object size: 5.8 Mb 

Testing setDT method...
setDT object size: 5.8 Mb 

Testing as.data.table method...
as.data.table object size: 5.8 Mb 

Final memory state:
          used (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 1174432 62.8    2371894 126.7  2371894 126.7
Vcells 4319713 33.0   10146329  77.5  4555775  34.8
print("\nFinal Results:")
[1] "\nFinal Results:"
print(results)
                     method memory_mb time_secs final_size
fread                 fread      3.55    0.0231     5.5 Mb
read_csv           read_csv      2.23    0.2246     5.8 Mb
setDT                 setDT      2.38    0.0030     5.8 Mb
as_data_table as_data_table      2.32    0.0020     5.8 Mb

🔍 Investigation Exercise:

Without using any external resources, what can you discover about this dataset using data.table methods?

💡Think about….

  • How many observations and variables are there?

  • What types of data are present?

# Use these data.table commands to gather clues:

# Clue 1: Basic structure and dimensions
spotify_dt[, .N]  # Number of rows
[1] 9999
ncol(spotify_dt)  # Number of columns
[1] 30
# Clue 2: Column names and types
spotify_dt[, lapply(.SD, class)]  # Shows class of each column
   track_name artist_name_s album_name album_artist_name_s album_release_date
       <char>        <char>     <char>              <char>             <char>
1:  character     character  character           character          character
2:  character     character  character           character          character
   disc_number track_number track_duration_ms explicit popularity      isrc
        <char>       <char>            <char>   <char>     <char>    <char>
1:     integer      integer           integer  logical    integer character
2:     integer      integer           integer  logical    integer character
    added_by added_at artist_genres danceability  energy     key loudness
      <char>   <char>        <char>       <char>  <char>  <char>   <char>
1: character  POSIXct     character      numeric numeric integer  numeric
2: character   POSIXt     character      numeric numeric integer  numeric
      mode speechiness acousticness instrumentalness liveness valence   tempo
    <char>      <char>       <char>           <char>   <char>  <char>  <char>
1: integer     numeric      numeric          numeric  numeric numeric numeric
2: integer     numeric      numeric          numeric  numeric numeric numeric
   time_signature album_genres     label copyrights main_genre
           <char>       <char>    <char>     <char>     <char>
1:        integer      logical character  character  character
2:        integer      logical character  character  character
#Clure 3: look at data content
spotify_dt[1:5]
                                track_name      artist_name_s
                                    <char>             <char>
1: Justified & Ancient - Stand by the Jams            The KLF
2:         I Know You Want Me (Calle Ocho)            Pitbull
3:      From the Bottom of My Broken Heart     Britney Spears
4:        Apeman - 2014 Remastered Version          The Kinks
5:      You Can't Always Get What You Want The Rolling Stones
                                                               album_name
                                                                   <char>
1:                                                       Songs Collection
2:                                         Pitbull Starring In Rebelution
3:                         ...Baby One More Time (Digital Deluxe Version)
4: Lola vs. Powerman and the Moneygoround, Pt. One + Percy (Super Deluxe)
5:                                                           Let It Bleed
   album_artist_name_s album_release_date disc_number track_number
                <char>             <char>       <int>        <int>
1:             The KLF         1992-08-03           1            3
2:             Pitbull         2009-10-23           1            3
3:      Britney Spears         1999-01-12           1            6
4:           The Kinks         2014-10-20           1           11
5:  The Rolling Stones         1969-12-05           1            9
   track_duration_ms explicit popularity         isrc                 added_by
               <int>   <lgcl>      <int>       <char>                   <char>
1:            216270    FALSE          0 QMARG1760056 spotify:user:bradnumber1
2:            237120    FALSE         64 USJAY0900144 spotify:user:bradnumber1
3:            312533    FALSE         56 USJI19910455 spotify:user:bradnumber1
4:            233400    FALSE         42 GB5KW1499822 spotify:user:bradnumber1
5:            448720    FALSE          0 USA176910100 spotify:user:bradnumber1
              added_at
                <POSc>
1: 2020-03-05 09:20:39
2: 2021-08-08 09:26:31
3: 2021-08-08 09:26:31
4: 2021-08-08 09:26:31
5: 2021-08-08 09:26:31
                                                                                                             artist_genres
                                                                                                                    <char>
1:                                                                             acid house,ambient house,big beat,hip house
2:                                                                                             dance pop,miami hip hop,pop
3:                                                                                                           dance pop,pop
4: album rock,art rock,british invasion,classic rock,folk rock,glam rock,protopunk,psychedelic rock,rock,singer-songwriter
5:                                                                           album rock,british invasion,classic rock,rock
   danceability energy   key loudness  mode speechiness acousticness
          <num>  <num> <int>    <num> <int>       <num>        <num>
1:        0.617  0.872     8  -12.305     1      0.0480       0.0158
2:        0.825  0.743     2   -5.995     1      0.1490       0.0142
3:        0.677  0.665     7   -5.171     1      0.0305       0.5600
4:        0.683  0.728     9   -8.920     1      0.2590       0.5680
5:        0.319  0.627     0   -9.611     1      0.0687       0.6750
   instrumentalness liveness valence   tempo time_signature album_genres
              <num>    <num>   <num>   <num>          <int>       <lgcl>
1:         1.12e-01   0.4080   0.504 111.458              4           NA
2:         2.12e-05   0.2370   0.800 127.045              4           NA
3:         1.01e-06   0.3380   0.706  74.981              4           NA
4:         5.08e-05   0.0384   0.833  75.311              4           NA
5:         7.29e-05   0.2890   0.497  85.818              4           NA
                                 label
                                <char>
1:                 Jams Communications
2: Mr.305/Polo Grounds Music/J Records
3:                                Jive
4:                   Sanctuary Records
5:               Universal Music Group
                                                                                                   copyrights
                                                                                                       <char>
1:                                                       C 1992 Copyright Control, P 1992 Jams Communications
2:                                        P (P) 2009 RCA/JIVE Label Group, a unit of Sony Music Entertainment
3:                                                                             P (P) 1999 Zomba Recording LLC
4: C © 2014 Sanctuary Records Group Ltd., a BMG Company, P ℗ 2014 Sanctuary Records Group Ltd., a BMG Company
5:                                   C © 2002 ABKCO Music & Records Inc., P ℗ 2002 ABKCO Music & Records Inc.
         main_genre
             <char>
1: Dance/Electronic
2:              Pop
3:              Pop
4:             Rock
5:             Rock
# Clue 4: Unique values in categorical columns
spotify_dt[, lapply(.SD, function(x) uniqueN(x)), .SDcols = is.character]
   track_name artist_name_s album_name album_artist_name_s album_release_date
        <int>         <int>      <int>               <int>              <int>
1:       8259          4130       6636                3295               3333
    isrc added_by artist_genres label copyrights main_genre
   <int>    <int>         <int> <int>      <int>      <int>
1:  8949        1          2816  1467       5379         10

Data.table Operations - data.table Syntax: [ i, j, by ]

Now let’s explore data.table’s powerful syntax for data manipulation. Think of these operations as your detective’s toolkit:

  • i (WHERE): Your filter 🔍 (selects specific rows)(like filter() & selec())

  • j (SELECT): Your magnifying glass 🔬 (focuses on specific columns or computations) (like select() or summarize())

  • by (GROUP BY): Your filing system 📁 (organizes findings)(like group_by())

1.) Basic Operations

  1. Selecting Rows (i)

When you only specify i, data.table returns a data.table (like a data frame), not a vector.

# Select first 5 rows
spotify_dt[1:5]
                                track_name      artist_name_s
                                    <char>             <char>
1: Justified & Ancient - Stand by the Jams            The KLF
2:         I Know You Want Me (Calle Ocho)            Pitbull
3:      From the Bottom of My Broken Heart     Britney Spears
4:        Apeman - 2014 Remastered Version          The Kinks
5:      You Can't Always Get What You Want The Rolling Stones
                                                               album_name
                                                                   <char>
1:                                                       Songs Collection
2:                                         Pitbull Starring In Rebelution
3:                         ...Baby One More Time (Digital Deluxe Version)
4: Lola vs. Powerman and the Moneygoround, Pt. One + Percy (Super Deluxe)
5:                                                           Let It Bleed
   album_artist_name_s album_release_date disc_number track_number
                <char>             <char>       <int>        <int>
1:             The KLF         1992-08-03           1            3
2:             Pitbull         2009-10-23           1            3
3:      Britney Spears         1999-01-12           1            6
4:           The Kinks         2014-10-20           1           11
5:  The Rolling Stones         1969-12-05           1            9
   track_duration_ms explicit popularity         isrc                 added_by
               <int>   <lgcl>      <int>       <char>                   <char>
1:            216270    FALSE          0 QMARG1760056 spotify:user:bradnumber1
2:            237120    FALSE         64 USJAY0900144 spotify:user:bradnumber1
3:            312533    FALSE         56 USJI19910455 spotify:user:bradnumber1
4:            233400    FALSE         42 GB5KW1499822 spotify:user:bradnumber1
5:            448720    FALSE          0 USA176910100 spotify:user:bradnumber1
              added_at
                <POSc>
1: 2020-03-05 09:20:39
2: 2021-08-08 09:26:31
3: 2021-08-08 09:26:31
4: 2021-08-08 09:26:31
5: 2021-08-08 09:26:31
                                                                                                             artist_genres
                                                                                                                    <char>
1:                                                                             acid house,ambient house,big beat,hip house
2:                                                                                             dance pop,miami hip hop,pop
3:                                                                                                           dance pop,pop
4: album rock,art rock,british invasion,classic rock,folk rock,glam rock,protopunk,psychedelic rock,rock,singer-songwriter
5:                                                                           album rock,british invasion,classic rock,rock
   danceability energy   key loudness  mode speechiness acousticness
          <num>  <num> <int>    <num> <int>       <num>        <num>
1:        0.617  0.872     8  -12.305     1      0.0480       0.0158
2:        0.825  0.743     2   -5.995     1      0.1490       0.0142
3:        0.677  0.665     7   -5.171     1      0.0305       0.5600
4:        0.683  0.728     9   -8.920     1      0.2590       0.5680
5:        0.319  0.627     0   -9.611     1      0.0687       0.6750
   instrumentalness liveness valence   tempo time_signature album_genres
              <num>    <num>   <num>   <num>          <int>       <lgcl>
1:         1.12e-01   0.4080   0.504 111.458              4           NA
2:         2.12e-05   0.2370   0.800 127.045              4           NA
3:         1.01e-06   0.3380   0.706  74.981              4           NA
4:         5.08e-05   0.0384   0.833  75.311              4           NA
5:         7.29e-05   0.2890   0.497  85.818              4           NA
                                 label
                                <char>
1:                 Jams Communications
2: Mr.305/Polo Grounds Music/J Records
3:                                Jive
4:                   Sanctuary Records
5:               Universal Music Group
                                                                                                   copyrights
                                                                                                       <char>
1:                                                       C 1992 Copyright Control, P 1992 Jams Communications
2:                                        P (P) 2009 RCA/JIVE Label Group, a unit of Sony Music Entertainment
3:                                                                             P (P) 1999 Zomba Recording LLC
4: C © 2014 Sanctuary Records Group Ltd., a BMG Company, P ℗ 2014 Sanctuary Records Group Ltd., a BMG Company
5:                                   C © 2002 ABKCO Music & Records Inc., P ℗ 2002 ABKCO Music & Records Inc.
         main_genre
             <char>
1: Dance/Electronic
2:              Pop
3:              Pop
4:             Rock
5:             Rock
# Filter by popularity
spotify_dt[popularity > 75]
                                 track_name                       artist_name_s
                                     <char>                              <char>
   1:            Don't Stop - 2004 Remaster                       Fleetwood Mac
   2:       Eastside (with Halsey & Khalid)        benny blanco, Halsey, Khalid
   3:                      Here Without You                        3 Doors Down
   4:    We Will Rock You - Remastered 2011                               Queen
   5:                  Too Good At Goodbyes                           Sam Smith
  ---                                                                          
1013: B.O.T.A. (Baddest Of Them All) - Edit Eliza Rose, Interplanetary Criminal
1014:                   Push Up - Main Edit                              Creeds
1015:                    Baby Don't Hurt Me David Guetta, Anne-Marie, Coi Leray
1016:          Kernkraft 400 (A Better Day)                          Topic, A7S
1017:                               Lay Low                              Tiësto
                                  album_name
                                      <char>
   1:                                Rumours
   2:        Eastside (with Halsey & Khalid)
   3:                      Away From The Sun
   4:      News Of The World (2011 Remaster)
   5: The Thrill Of It All (Special Edition)
  ---                                       
1013:         B.O.T.A. (Baddest Of Them All)
1014:                    Push Up (Main Edit)
1015:                     Baby Don't Hurt Me
1016:           Kernkraft 400 (A Better Day)
1017:                                Lay Low
                      album_artist_name_s album_release_date disc_number
                                   <char>             <char>       <int>
   1:                       Fleetwood Mac         1977-02-04           1
   2:        benny blanco, Halsey, Khalid         2018-07-12           1
   3:                        3 Doors Down         2002-11-12           1
   4:                               Queen         1977-10-28           1
   5:                           Sam Smith         2017-11-03           1
  ---                                                                   
1013: Eliza Rose, Interplanetary Criminal         2022-08-12           1
1014:                              Creeds         2023-03-31           1
1015: David Guetta, Anne-Marie, Coi Leray         2023-04-06           1
1016:                          Topic, A7S         2022-06-17           1
1017:                              Tiësto         2023-01-06           1
      track_number track_duration_ms explicit popularity         isrc
             <int>             <int>   <lgcl>      <int>       <char>
   1:            4            193346    FALSE         79 USWB10400049
   2:            1            173799    FALSE         78 USUM71809132
   3:            6            238733    FALSE         80 USUR10200764
   4:            1            122066    FALSE         82 GBUM71029618
   5:            1            201000    FALSE         87 GBUM71704089
  ---                                                                
1013:            1            226626    FALSE         82 QZAKB2166405
1014:            1            139300    FALSE         86 DEE862300564
1015:            1            140017    FALSE         94 UKWLG2300016
1016:            1            165800    FALSE         79 DECE72201091
1017:            1            153442    FALSE         87 NLZ542202348
                      added_by            added_at
                        <char>              <POSc>
   1: spotify:user:bradnumber1 2022-08-31 00:08:18
   2: spotify:user:bradnumber1 2021-08-08 09:26:31
   3: spotify:user:bradnumber1 2021-08-08 09:26:31
   4: spotify:user:bradnumber1 2021-08-08 09:26:31
   5: spotify:user:bradnumber1 2021-08-08 09:26:31
  ---                                             
1013: spotify:user:bradnumber1 2023-07-09 01:59:43
1014: spotify:user:bradnumber1 2023-07-11 01:16:38
1015: spotify:user:bradnumber1 2023-07-11 05:37:45
1016: spotify:user:bradnumber1 2023-07-11 10:57:25
1017: spotify:user:bradnumber1 2023-07-18 22:06:36
                                                                       artist_genres
                                                                              <char>
   1:                              album rock,classic rock,rock,soft rock,yacht rock
   2:                        pop,electropop,etherpop,indie poptimism,pop,pop,pop r&b
   3:                                    alternative metal,nu metal,post-grunge,rock
   4:                                                    classic rock,glam rock,rock
   5:                                                                     pop,uk pop
  ---                                                                               
1013:                                                house,breaks,experimental house
1014:                                                                           <NA>
1015: big room,dance pop,edm,pop,pop dance,pop,new jersey underground rap,trap queen
1016:           german dance,pop dance,pop edm,uk dance,pop dance,scandipop,uk dance
1017:               big room,brostep,dutch edm,edm,house,pop dance,slap house,trance
      danceability energy   key loudness  mode speechiness acousticness
             <num>  <num> <int>    <num> <int>       <num>        <num>
   1:        0.671  0.710     9   -7.724     1      0.0356      0.03930
   2:        0.560  0.680     6   -7.648     0      0.3210      0.55500
   3:        0.557  0.533    10   -6.817     0      0.0252      0.04920
   4:        0.692  0.497     2   -7.316     1      0.1190      0.67600
   5:        0.681  0.372     5   -8.237     1      0.0432      0.64000
  ---                                                                  
1013:        0.736  0.906     0   -7.589     1      0.0480      0.16400
1014:        0.767  0.830     7   -8.780     1      0.2060      0.20900
1015:        0.602  0.910     7   -3.404     1      0.0308      0.00126
1016:        0.623  0.727    11   -5.570     0      0.0562      0.18400
1017:        0.534  0.855     1   -4.923     0      0.1830      0.06070
      instrumentalness liveness valence   tempo time_signature album_genres
                 <num>    <num>   <num>   <num>          <int>       <lgcl>
   1:         1.12e-05   0.0387   0.834 118.745              4           NA
   2:         0.00e+00   0.1160   0.319  89.391              4           NA
   3:         0.00e+00   0.2050   0.233 143.994              4           NA
   4:         0.00e+00   0.2590   0.475  81.308              4           NA
   5:         0.00e+00   0.1690   0.476  91.873              4           NA
  ---                                                                      
1013:         5.85e-01   0.1060   0.698 137.001              4           NA
1014:         8.36e-01   0.0582   0.187  75.023              4           NA
1015:         1.74e-04   0.1200   0.228 127.944              4           NA
1016:         2.02e-05   0.3090   0.400 125.975              4           NA
1017:         2.63e-04   0.3460   0.420 122.060              4           NA
                           label
                          <char>
   1:       Rhino/Warner Records
   2: Benny Blanco Solo Album PS
   3:          Universal Records
   4:                        EMI
   5:                    Capitol
  ---                           
1013:             Warner Records
1014:     Columbia/B1 Recordings
1015:              Parlophone UK
1016:                     Virgin
1017:            Musical Freedom
                                                                                                                                                                                    copyrights
                                                                                                                                                                                        <char>
   1:                                                                                                                               C © 2004 Warner Records Inc., P ℗ 2004 Warner Records Inc.
   2:                                                                                       C © 2018 Friends Keep Secrets/Interscope Records, P ℗ 2018 Friends Keep Secrets/Interscope Records
   3:                                                    C © 2002 Universal Records, a Division of UMG Recordings, Inc., P ℗ 2002 Universal Motown Records, a division of UMG Recordings, Inc.
   4: C © 2011 Queen Productions Ltd. under exclusive licence to Universal International Music BV, P ℗ 2011 Queen Productions Ltd. under exclusive licence to Universal International Music BV
   5:                                                                                                 C © 2017 Universal Music Operations Limited, P ℗ 2017 Universal Music Operations Limited
  ---                                                                                                                                                                                         
1013:                       C Under exclusive licence to Warner Music UK Limited, © 2022 One House X Limited, P Under exclusive licence to Warner Music UK Limited, ℗ 2022 One House X Limited
1014:                                       P (P) 2023 Rave Alert Records, under exclusive license to Ministry of Sound/Arista Records/B1 Recordings GmbH, a Sony Music Entertainment company.
1015:                                                       C Under license to Warner Music UK Limited, © 2023 What A DJ Ltd, P Under license to Warner Music UK Limited, ℗ 2023 What A DJ Ltd
1016:                                                         C © 2022 Topic, under exclusive license to Universal Music GmbH, P ℗ 2022 Topic, under exclusive license to Universal Music GmbH
1017:                                                                                                                 C © 2023 Musical Freedom Label Ltd., P ℗ 2023 Musical Freedom Label Ltd.
            main_genre
                <char>
   1:             Rock
   2:              Pop
   3:             Rock
   4:             Rock
   5:              Pop
  ---                 
1013: Dance/Electronic
1014:            Other
1015:              Pop
1016:              Pop
1017:              Pop
# Multiple conditions
spotify_dt[popularity > 75 & main_genre == "Rock"]
                             track_name               artist_name_s
                                 <char>                      <char>
  1:         Don't Stop - 2004 Remaster               Fleetwood Mac
  2:                   Here Without You                3 Doors Down
  3: We Will Rock You - Remastered 2011                       Queen
  4:                            My Hero                Foo Fighters
  5:                I Love Rock 'N Roll Joan Jett & the Blackhearts
 ---                                                               
230:                    One Step Closer                 Linkin Park
231:  Good Riddance (Time of Your Life)                   Green Day
232:                 When I Come Around                   Green Day
233:        Rebel Rebel - 2016 Remaster                 David Bowie
234:                           Rhiannon               Fleetwood Mac
                                  album_name         album_artist_name_s
                                      <char>                      <char>
  1:                                 Rumours               Fleetwood Mac
  2:                       Away From The Sun                3 Doors Down
  3:       News Of The World (2011 Remaster)                       Queen
  4:                The Colour And The Shape                Foo Fighters
  5: I Love Rock 'N' Roll (Expanded Edition) Joan Jett & the Blackhearts
 ---                                                                    
230:           Hybrid Theory (Bonus Edition)                 Linkin Park
231:                                  Nimrod                   Green Day
232:                                  Dookie                   Green Day
233:            Diamond Dogs (2016 Remaster)                 David Bowie
234:                           Fleetwood Mac               Fleetwood Mac
     album_release_date disc_number track_number track_duration_ms explicit
                 <char>       <int>        <int>             <int>   <lgcl>
  1:         1977-02-04           1            4            193346    FALSE
  2:         2002-11-12           1            6            238733    FALSE
  3:         1977-10-28           1            1            122066    FALSE
  4:         1997-05-20           1            7            260026    FALSE
  5:         1981-11-18           1            1            175173    FALSE
 ---                                                                       
230:         2000-10-24           1            2            157333    FALSE
231:         1997-10-14           1           17            153466     TRUE
232:         1994-02-01           1           10            178000    FALSE
233:         1974-05-24           1            6            274746    FALSE
234:         1975-07-11           1            4            252773    FALSE
     popularity         isrc                 added_by            added_at
          <int>       <char>                   <char>              <POSc>
  1:         79 USWB10400049 spotify:user:bradnumber1 2022-08-31 00:08:18
  2:         80 USUR10200764 spotify:user:bradnumber1 2021-08-08 09:26:31
  3:         82 GBUM71029618 spotify:user:bradnumber1 2021-08-08 09:26:31
  4:         79 USRW29600007 spotify:user:bradnumber1 2021-08-08 09:26:31
  5:         81 USBH18100118 spotify:user:bradnumber1 2021-08-08 09:26:31
 ---                                                                     
230:         83 USWB10002399 spotify:user:bradnumber1 2021-08-08 09:26:31
231:         82 USRE19700545 spotify:user:bradnumber1 2021-08-08 09:26:31
232:         80 USRE19900154 spotify:user:bradnumber1 2021-08-08 09:26:31
233:         76 USJT11600006 spotify:user:bradnumber1 2021-08-08 09:26:31
234:         77 USWB19900188 spotify:user:bradnumber1 2021-08-08 09:26:31
                                                                      artist_genres
                                                                             <char>
  1:                              album rock,classic rock,rock,soft rock,yacht rock
  2:                                    alternative metal,nu metal,post-grunge,rock
  3:                                                    classic rock,glam rock,rock
  4: alternative metal,alternative rock,modern rock,permanent wave,post-grunge,rock
  5:                                                                 glam punk,rock
 ---                                                                               
230:                          alternative metal,nu metal,post-grunge,rap metal,rock
231:                                           modern rock,permanent wave,punk,rock
232:                                           modern rock,permanent wave,punk,rock
233:                            art rock,classic rock,glam rock,permanent wave,rock
234:                              album rock,classic rock,rock,soft rock,yacht rock
     danceability energy   key loudness  mode speechiness acousticness
            <num>  <num> <int>    <num> <int>       <num>        <num>
  1:        0.671  0.710     9   -7.724     1      0.0356     0.039300
  2:        0.557  0.533    10   -6.817     0      0.0252     0.049200
  3:        0.692  0.497     2   -7.316     1      0.1190     0.676000
  4:        0.398  0.927     9   -4.212     1      0.0567     0.000062
  5:        0.535  0.716     4   -5.025     1      0.0431     0.326000
 ---                                                                  
230:        0.492  0.969     9   -4.419     1      0.0491     0.001400
231:        0.475  0.432     7   -7.844     1      0.0302     0.183000
232:        0.531  0.909    11   -4.236     1      0.0340     0.017500
233:        0.635  0.686     9  -15.648     1      0.0530     0.209000
234:        0.723  0.490     9  -14.745     0      0.0296     0.111000
     instrumentalness liveness valence   tempo time_signature album_genres
                <num>    <num>   <num>   <num>          <int>       <lgcl>
  1:         1.12e-05   0.0387   0.834 118.745              4           NA
  2:         0.00e+00   0.2050   0.233 143.994              4           NA
  3:         0.00e+00   0.2590   0.475  81.308              4           NA
  4:         1.77e-04   0.0575   0.311  77.106              4           NA
  5:         0.00e+00   0.6590   0.901  94.379              4           NA
 ---                                                                      
230:         1.32e-06   0.0787   0.538  95.136              4           NA
231:         0.00e+00   0.1610   0.648  94.605              4           NA
232:         0.00e+00   0.2310   0.814  97.546              4           NA
233:         1.76e-02   0.2820   0.464 125.988              4           NA
234:         9.46e-02   0.0923   0.795 129.012              4           NA
                    label
                   <char>
  1: Rhino/Warner Records
  2:    Universal Records
  3:                  EMI
  4:    RCA Records Label
  5:    Legacy Recordings
 ---                     
230:       Warner Records
231:              Reprise
232:              Reprise
233:        Parlophone UK
234:       Warner Records
                                                                                                                                                                                                 copyrights
                                                                                                                                                                                                     <char>
  1:                                                                                                                                             C © 2004 Warner Records Inc., P ℗ 2004 Warner Records Inc.
  2:                                                                  C © 2002 Universal Records, a Division of UMG Recordings, Inc., P ℗ 2002 Universal Motown Records, a division of UMG Recordings, Inc.
  3:               C © 2011 Queen Productions Ltd. under exclusive licence to Universal International Music BV, P ℗ 2011 Queen Productions Ltd. under exclusive licence to Universal International Music BV
  4:                                                                                                                                                                       P (P) 1997 Roswell Records, Inc.
  5:                                                                                                               P (P) 1981 Blackheart Records Group, under exclusive license to Sony Music Entertainment
 ---                                                                                                                                                                                                       
230:                                                                                                                                             C © 2000 Warner Records Inc., P ℗ 2000 Warner Records Inc.
231: C © 1997 Reprise Records for the U.S. and WEA International Inc. for the world outside of the U.S., P ℗ 1997 Reprise Records for the U.S. and WEA International Inc. for the world outside of the U.S.
232: C © 1994 Reprise Records for the U.S. and WEA International Inc. for the world outside of the U.S., P ℗ 1994 Reprise Records for the U.S. and WEA International Inc. for the world outside of the U.S.
233:               C © 2016 Jones/Tintoretto Entertainment Co. LLC., P ℗ 1974, 2016 Jones/Tintoretto Entertainment Co., LLC under exclusive license to Parlophone Records Ltd, a Warner Music Group Company
234:                                                                                                                                             C © 1975 Warner Records Inc., P ℗ 1975 Warner Records Inc.
     main_genre
         <char>
  1:       Rock
  2:       Rock
  3:       Rock
  4:       Rock
  5:       Rock
 ---           
230:       Rock
231:       Rock
232:       Rock
233:       Rock
234:       Rock
# Excluding certain values
spotify_dt[key != 10]
                                                      track_name
                                                          <char>
   1:                    Justified & Ancient - Stand by the Jams
   2:                            I Know You Want Me (Calle Ocho)
   3:                         From the Bottom of My Broken Heart
   4:                           Apeman - 2014 Remastered Version
   5:                         You Can't Always Get What You Want
  ---                                                           
9375:                               Kernkraft 400 (A Better Day)
9376:                               Never Say Never - Radio Edit
9377: Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
9378:                                                    Lay Low
9379:                                                Padam Padam
                     artist_name_s
                            <char>
   1:                      The KLF
   2:                      Pitbull
   3:               Britney Spears
   4:                    The Kinks
   5:           The Rolling Stones
  ---                             
9375:                   Topic, A7S
9376:                    Vandalism
9377: Spiller, Sophie Ellis-Bextor
9378:                       Tiësto
9379:                Kylie Minogue
                                                                  album_name
                                                                      <char>
   1:                                                       Songs Collection
   2:                                         Pitbull Starring In Rebelution
   3:                         ...Baby One More Time (Digital Deluxe Version)
   4: Lola vs. Powerman and the Moneygoround, Pt. One + Percy (Super Deluxe)
   5:                                                           Let It Bleed
  ---                                                                       
9375:                                           Kernkraft 400 (A Better Day)
9376:                                                        Never Say Never
9377:             Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
9378:                                                                Lay Low
9379:                                                            Padam Padam
      album_artist_name_s album_release_date disc_number track_number
                   <char>             <char>       <int>        <int>
   1:             The KLF         1992-08-03           1            3
   2:             Pitbull         2009-10-23           1            3
   3:      Britney Spears         1999-01-12           1            6
   4:           The Kinks         2014-10-20           1           11
   5:  The Rolling Stones         1969-12-05           1            9
  ---                                                                
9375:          Topic, A7S         2022-06-17           1            1
9376:           Vandalism         2005-10-24           1            1
9377:             Spiller         2000-08-14           1            1
9378:              Tiësto         2023-01-06           1            1
9379:       Kylie Minogue         2023-05-19           1            1
      track_duration_ms explicit popularity         isrc
                  <int>   <lgcl>      <int>       <char>
   1:            216270    FALSE          0 QMARG1760056
   2:            237120    FALSE         64 USJAY0900144
   3:            312533    FALSE         56 USJI19910455
   4:            233400    FALSE         42 GB5KW1499822
   5:            448720    FALSE          0 USA176910100
  ---                                                   
9375:            165800    FALSE         79 DECE72201091
9376:            176640    FALSE         17 AUVC00503711
9377:            227619    FALSE         62 GBCPZ0019728
9378:            153442    FALSE         87 NLZ542202348
9379:            166266    FALSE         69 GB5KW2301017
                      added_by            added_at
                        <char>              <POSc>
   1: spotify:user:bradnumber1 2020-03-05 09:20:39
   2: spotify:user:bradnumber1 2021-08-08 09:26:31
   3: spotify:user:bradnumber1 2021-08-08 09:26:31
   4: spotify:user:bradnumber1 2021-08-08 09:26:31
   5: spotify:user:bradnumber1 2021-08-08 09:26:31
  ---                                             
9375: spotify:user:bradnumber1 2023-07-11 10:57:25
9376: spotify:user:bradnumber1 2023-07-16 09:38:19
9377: spotify:user:bradnumber1 2023-07-16 09:39:17
9378: spotify:user:bradnumber1 2023-07-18 22:06:36
9379: spotify:user:bradnumber1 2023-07-25 11:57:02
                                                                                                                artist_genres
                                                                                                                       <char>
   1:                                                                             acid house,ambient house,big beat,hip house
   2:                                                                                             dance pop,miami hip hop,pop
   3:                                                                                                           dance pop,pop
   4: album rock,art rock,british invasion,classic rock,folk rock,glam rock,protopunk,psychedelic rock,rock,singer-songwriter
   5:                                                                           album rock,british invasion,classic rock,rock
  ---                                                                                                                        
9375:                                                    german dance,pop dance,pop edm,uk dance,pop dance,scandipop,uk dance
9376:                                                                                       australian dance,melbourne bounce
9377:                                                                  disco house,vocal house,dance pop,europop,new wave pop
9378:                                                        big room,brostep,dutch edm,edm,house,pop dance,slap house,trance
9379:                                                        australian dance,australian pop,dance pop,eurodance,new wave pop
      danceability energy   key loudness  mode speechiness acousticness
             <num>  <num> <int>    <num> <int>       <num>        <num>
   1:        0.617  0.872     8  -12.305     1      0.0480     0.015800
   2:        0.825  0.743     2   -5.995     1      0.1490     0.014200
   3:        0.677  0.665     7   -5.171     1      0.0305     0.560000
   4:        0.683  0.728     9   -8.920     1      0.2590     0.568000
   5:        0.319  0.627     0   -9.611     1      0.0687     0.675000
  ---                                                                  
9375:        0.623  0.727    11   -5.570     0      0.0562     0.184000
9376:        0.720  0.841     9   -6.373     1      0.0340     0.000354
9377:        0.719  0.806     9   -6.802     0      0.0389     0.000132
9378:        0.534  0.855     1   -4.923     0      0.1830     0.060700
9379:        0.744  0.620     5   -7.930     1      0.2460     0.214000
      instrumentalness liveness valence   tempo time_signature album_genres
                 <num>    <num>   <num>   <num>          <int>       <lgcl>
   1:         1.12e-01   0.4080   0.504 111.458              4           NA
   2:         2.12e-05   0.2370   0.800 127.045              4           NA
   3:         1.01e-06   0.3380   0.706  74.981              4           NA
   4:         5.08e-05   0.0384   0.833  75.311              4           NA
   5:         7.29e-05   0.2890   0.497  85.818              4           NA
  ---                                                                      
9375:         2.02e-05   0.3090   0.400 125.975              4           NA
9376:         1.12e-02   0.3380   0.767 130.978              4           NA
9377:         8.89e-02   0.3610   0.626 123.037              4           NA
9378:         2.63e-04   0.3460   0.420 122.060              4           NA
9379:         1.16e-03   0.1030   0.711 128.103              4           NA
                                    label
                                   <char>
   1:                 Jams Communications
   2: Mr.305/Polo Grounds Music/J Records
   3:                                Jive
   4:                   Sanctuary Records
   5:               Universal Music Group
  ---                                    
9375:                              Virgin
9376:                             Vicious
9377:                    Defected Records
9378:                     Musical Freedom
9379:                     Liberator Music
                                                                                                                                                                                    copyrights
                                                                                                                                                                                        <char>
   1:                                                                                                                                     C 1992 Copyright Control, P 1992 Jams Communications
   2:                                                                                                                      P (P) 2009 RCA/JIVE Label Group, a unit of Sony Music Entertainment
   3:                                                                                                                                                           P (P) 1999 Zomba Recording LLC
   4:                                                                               C © 2014 Sanctuary Records Group Ltd., a BMG Company, P ℗ 2014 Sanctuary Records Group Ltd., a BMG Company
   5:                                                                                                                 C © 2002 ABKCO Music & Records Inc., P ℗ 2002 ABKCO Music & Records Inc.
  ---                                                                                                                                                                                         
9375:                                                         C © 2022 Topic, under exclusive license to Universal Music GmbH, P ℗ 2022 Topic, under exclusive license to Universal Music GmbH
9376:                                                                       C 2005 Vicious, a division of Vicious Recordings Pty Ltd, P 2005 Vicious, a division of Vicious Recordings Pty Ltd
9377:                                                                                                                     C © 2021 Defected Records Limited, P ℗ 2021 Defected Records Limited
9378:                                                                                                                 C © 2023 Musical Freedom Label Ltd., P ℗ 2023 Musical Freedom Label Ltd.
9379: C 2023 Kylie Minogue/Darenote under exclusive license to BMG Rights Management (UK) Limited, P 2023 Kylie Minogue/Darenote under exclusive license to BMG Rights Management (UK) Limited
            main_genre
                <char>
   1: Dance/Electronic
   2:              Pop
   3:              Pop
   4:             Rock
   5:             Rock
  ---                 
9375:              Pop
9376: Dance/Electronic
9377:              Pop
9378:              Pop
9379:              Pop
# Select tracks by genre
spotify_dt[main_genre %in% c("Rock", "Pop")]
                                                      track_name
                                                          <char>
   1:                            I Know You Want Me (Calle Ocho)
   2:                         From the Bottom of My Broken Heart
   3:                           Apeman - 2014 Remastered Version
   4:                         You Can't Always Get What You Want
   5:                                 Don't Stop - 2004 Remaster
  ---                                                           
8103:                                         Baby Don't Hurt Me
8104:                               Kernkraft 400 (A Better Day)
8105: Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
8106:                                                    Lay Low
8107:                                                Padam Padam
                            artist_name_s
                                   <char>
   1:                             Pitbull
   2:                      Britney Spears
   3:                           The Kinks
   4:                  The Rolling Stones
   5:                       Fleetwood Mac
  ---                                    
8103: David Guetta, Anne-Marie, Coi Leray
8104:                          Topic, A7S
8105:        Spiller, Sophie Ellis-Bextor
8106:                              Tiësto
8107:                       Kylie Minogue
                                                                  album_name
                                                                      <char>
   1:                                         Pitbull Starring In Rebelution
   2:                         ...Baby One More Time (Digital Deluxe Version)
   3: Lola vs. Powerman and the Moneygoround, Pt. One + Percy (Super Deluxe)
   4:                                                           Let It Bleed
   5:                                                                Rumours
  ---                                                                       
8103:                                                     Baby Don't Hurt Me
8104:                                           Kernkraft 400 (A Better Day)
8105:             Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
8106:                                                                Lay Low
8107:                                                            Padam Padam
                      album_artist_name_s album_release_date disc_number
                                   <char>             <char>       <int>
   1:                             Pitbull         2009-10-23           1
   2:                      Britney Spears         1999-01-12           1
   3:                           The Kinks         2014-10-20           1
   4:                  The Rolling Stones         1969-12-05           1
   5:                       Fleetwood Mac         1977-02-04           1
  ---                                                                   
8103: David Guetta, Anne-Marie, Coi Leray         2023-04-06           1
8104:                          Topic, A7S         2022-06-17           1
8105:                             Spiller         2000-08-14           1
8106:                              Tiësto         2023-01-06           1
8107:                       Kylie Minogue         2023-05-19           1
      track_number track_duration_ms explicit popularity         isrc
             <int>             <int>   <lgcl>      <int>       <char>
   1:            3            237120    FALSE         64 USJAY0900144
   2:            6            312533    FALSE         56 USJI19910455
   3:           11            233400    FALSE         42 GB5KW1499822
   4:            9            448720    FALSE          0 USA176910100
   5:            4            193346    FALSE         79 USWB10400049
  ---                                                                
8103:            1            140017    FALSE         94 UKWLG2300016
8104:            1            165800    FALSE         79 DECE72201091
8105:            1            227619    FALSE         62 GBCPZ0019728
8106:            1            153442    FALSE         87 NLZ542202348
8107:            1            166266    FALSE         69 GB5KW2301017
                      added_by            added_at
                        <char>              <POSc>
   1: spotify:user:bradnumber1 2021-08-08 09:26:31
   2: spotify:user:bradnumber1 2021-08-08 09:26:31
   3: spotify:user:bradnumber1 2021-08-08 09:26:31
   4: spotify:user:bradnumber1 2021-08-08 09:26:31
   5: spotify:user:bradnumber1 2022-08-31 00:08:18
  ---                                             
8103: spotify:user:bradnumber1 2023-07-11 05:37:45
8104: spotify:user:bradnumber1 2023-07-11 10:57:25
8105: spotify:user:bradnumber1 2023-07-16 09:39:17
8106: spotify:user:bradnumber1 2023-07-18 22:06:36
8107: spotify:user:bradnumber1 2023-07-25 11:57:02
                                                                                                                artist_genres
                                                                                                                       <char>
   1:                                                                                             dance pop,miami hip hop,pop
   2:                                                                                                           dance pop,pop
   3: album rock,art rock,british invasion,classic rock,folk rock,glam rock,protopunk,psychedelic rock,rock,singer-songwriter
   4:                                                                           album rock,british invasion,classic rock,rock
   5:                                                                       album rock,classic rock,rock,soft rock,yacht rock
  ---                                                                                                                        
8103:                                          big room,dance pop,edm,pop,pop dance,pop,new jersey underground rap,trap queen
8104:                                                    german dance,pop dance,pop edm,uk dance,pop dance,scandipop,uk dance
8105:                                                                  disco house,vocal house,dance pop,europop,new wave pop
8106:                                                        big room,brostep,dutch edm,edm,house,pop dance,slap house,trance
8107:                                                        australian dance,australian pop,dance pop,eurodance,new wave pop
      danceability energy   key loudness  mode speechiness acousticness
             <num>  <num> <int>    <num> <int>       <num>        <num>
   1:        0.825  0.743     2   -5.995     1      0.1490     0.014200
   2:        0.677  0.665     7   -5.171     1      0.0305     0.560000
   3:        0.683  0.728     9   -8.920     1      0.2590     0.568000
   4:        0.319  0.627     0   -9.611     1      0.0687     0.675000
   5:        0.671  0.710     9   -7.724     1      0.0356     0.039300
  ---                                                                  
8103:        0.602  0.910     7   -3.404     1      0.0308     0.001260
8104:        0.623  0.727    11   -5.570     0      0.0562     0.184000
8105:        0.719  0.806     9   -6.802     0      0.0389     0.000132
8106:        0.534  0.855     1   -4.923     0      0.1830     0.060700
8107:        0.744  0.620     5   -7.930     1      0.2460     0.214000
      instrumentalness liveness valence   tempo time_signature album_genres
                 <num>    <num>   <num>   <num>          <int>       <lgcl>
   1:         2.12e-05   0.2370   0.800 127.045              4           NA
   2:         1.01e-06   0.3380   0.706  74.981              4           NA
   3:         5.08e-05   0.0384   0.833  75.311              4           NA
   4:         7.29e-05   0.2890   0.497  85.818              4           NA
   5:         1.12e-05   0.0387   0.834 118.745              4           NA
  ---                                                                      
8103:         1.74e-04   0.1200   0.228 127.944              4           NA
8104:         2.02e-05   0.3090   0.400 125.975              4           NA
8105:         8.89e-02   0.3610   0.626 123.037              4           NA
8106:         2.63e-04   0.3460   0.420 122.060              4           NA
8107:         1.16e-03   0.1030   0.711 128.103              4           NA
                                    label
                                   <char>
   1: Mr.305/Polo Grounds Music/J Records
   2:                                Jive
   3:                   Sanctuary Records
   4:               Universal Music Group
   5:                Rhino/Warner Records
  ---                                    
8103:                       Parlophone UK
8104:                              Virgin
8105:                    Defected Records
8106:                     Musical Freedom
8107:                     Liberator Music
                                                                                                                                                                                    copyrights
                                                                                                                                                                                        <char>
   1:                                                                                                                      P (P) 2009 RCA/JIVE Label Group, a unit of Sony Music Entertainment
   2:                                                                                                                                                           P (P) 1999 Zomba Recording LLC
   3:                                                                               C © 2014 Sanctuary Records Group Ltd., a BMG Company, P ℗ 2014 Sanctuary Records Group Ltd., a BMG Company
   4:                                                                                                                 C © 2002 ABKCO Music & Records Inc., P ℗ 2002 ABKCO Music & Records Inc.
   5:                                                                                                                               C © 2004 Warner Records Inc., P ℗ 2004 Warner Records Inc.
  ---                                                                                                                                                                                         
8103:                                                       C Under license to Warner Music UK Limited, © 2023 What A DJ Ltd, P Under license to Warner Music UK Limited, ℗ 2023 What A DJ Ltd
8104:                                                         C © 2022 Topic, under exclusive license to Universal Music GmbH, P ℗ 2022 Topic, under exclusive license to Universal Music GmbH
8105:                                                                                                                     C © 2021 Defected Records Limited, P ℗ 2021 Defected Records Limited
8106:                                                                                                                 C © 2023 Musical Freedom Label Ltd., P ℗ 2023 Musical Freedom Label Ltd.
8107: C 2023 Kylie Minogue/Darenote under exclusive license to BMG Rights Management (UK) Limited, P 2023 Kylie Minogue/Darenote under exclusive license to BMG Rights Management (UK) Limited
      main_genre
          <char>
   1:        Pop
   2:        Pop
   3:       Rock
   4:       Rock
   5:       Rock
  ---           
8103:        Pop
8104:        Pop
8105:        Pop
8106:        Pop
8107:        Pop

✅Now you try:

Selecting Rows (i)

# Select the last 5 rows
spotify_dt[9995:9999]
                                                   track_name
                                                       <char>
1:                               Kernkraft 400 (A Better Day)
2:                               Never Say Never - Radio Edit
3: Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
4:                                                    Lay Low
5:                                                Padam Padam
                  artist_name_s
                         <char>
1:                   Topic, A7S
2:                    Vandalism
3: Spiller, Sophie Ellis-Bextor
4:                       Tiësto
5:                Kylie Minogue
                                                   album_name
                                                       <char>
1:                               Kernkraft 400 (A Better Day)
2:                                            Never Say Never
3: Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
4:                                                    Lay Low
5:                                                Padam Padam
   album_artist_name_s album_release_date disc_number track_number
                <char>             <char>       <int>        <int>
1:          Topic, A7S         2022-06-17           1            1
2:           Vandalism         2005-10-24           1            1
3:             Spiller         2000-08-14           1            1
4:              Tiësto         2023-01-06           1            1
5:       Kylie Minogue         2023-05-19           1            1
   track_duration_ms explicit popularity         isrc                 added_by
               <int>   <lgcl>      <int>       <char>                   <char>
1:            165800    FALSE         79 DECE72201091 spotify:user:bradnumber1
2:            176640    FALSE         17 AUVC00503711 spotify:user:bradnumber1
3:            227619    FALSE         62 GBCPZ0019728 spotify:user:bradnumber1
4:            153442    FALSE         87 NLZ542202348 spotify:user:bradnumber1
5:            166266    FALSE         69 GB5KW2301017 spotify:user:bradnumber1
              added_at
                <POSc>
1: 2023-07-11 10:57:25
2: 2023-07-16 09:38:19
3: 2023-07-16 09:39:17
4: 2023-07-18 22:06:36
5: 2023-07-25 11:57:02
                                                          artist_genres
                                                                 <char>
1: german dance,pop dance,pop edm,uk dance,pop dance,scandipop,uk dance
2:                                    australian dance,melbourne bounce
3:               disco house,vocal house,dance pop,europop,new wave pop
4:     big room,brostep,dutch edm,edm,house,pop dance,slap house,trance
5:     australian dance,australian pop,dance pop,eurodance,new wave pop
   danceability energy   key loudness  mode speechiness acousticness
          <num>  <num> <int>    <num> <int>       <num>        <num>
1:        0.623  0.727    11   -5.570     0      0.0562     0.184000
2:        0.720  0.841     9   -6.373     1      0.0340     0.000354
3:        0.719  0.806     9   -6.802     0      0.0389     0.000132
4:        0.534  0.855     1   -4.923     0      0.1830     0.060700
5:        0.744  0.620     5   -7.930     1      0.2460     0.214000
   instrumentalness liveness valence   tempo time_signature album_genres
              <num>    <num>   <num>   <num>          <int>       <lgcl>
1:         2.02e-05    0.309   0.400 125.975              4           NA
2:         1.12e-02    0.338   0.767 130.978              4           NA
3:         8.89e-02    0.361   0.626 123.037              4           NA
4:         2.63e-04    0.346   0.420 122.060              4           NA
5:         1.16e-03    0.103   0.711 128.103              4           NA
              label
             <char>
1:           Virgin
2:          Vicious
3: Defected Records
4:  Musical Freedom
5:  Liberator Music
                                                                                                                                                                                 copyrights
                                                                                                                                                                                     <char>
1:                                                         C © 2022 Topic, under exclusive license to Universal Music GmbH, P ℗ 2022 Topic, under exclusive license to Universal Music GmbH
2:                                                                       C 2005 Vicious, a division of Vicious Recordings Pty Ltd, P 2005 Vicious, a division of Vicious Recordings Pty Ltd
3:                                                                                                                     C © 2021 Defected Records Limited, P ℗ 2021 Defected Records Limited
4:                                                                                                                 C © 2023 Musical Freedom Label Ltd., P ℗ 2023 Musical Freedom Label Ltd.
5: C 2023 Kylie Minogue/Darenote under exclusive license to BMG Rights Management (UK) Limited, P 2023 Kylie Minogue/Darenote under exclusive license to BMG Rights Management (UK) Limited
         main_genre
             <char>
1:              Pop
2: Dance/Electronic
3:              Pop
4:              Pop
5:              Pop
# Filter by energy and select the Pop genre
spotify_dt[energy < 0.25 & main_genre == "Pop"]
                                                    track_name
                                                        <char>
 1:                                             Sweet Caroline
 2:                                               Stay with Me
 3:                                           Unchained Melody
 4:                Don't Cry For Me Argentina - From ""Evita""
 5:                       Breakin' In A Brand New Broken Heart
 6:                                              Poison & Wine
 7: I See Fire - From ""The Hobbit - The Desolation Of Smaug""
 8:                                     I Will Always Love You
 9:                                          Dancing On My Own
10:                                          This Love of Mine
11:                                                    For You
12:                                                 Turn Me On
13:                                             Don't Know Why
14:                                         If I Only Had Time
15:                                     Nothing Really Matters
16:         So Sad (To Watch Good Love Go Bad) - 2007 Remaster
17:                                                    Kiss Me
18:                                        When I Fall in Love
19:                                                    Perfect
20:                                                Lost It All
21:             You Don't Bring Me Flowers (with Neil Diamond)
22:                                          Dancing On My Own
23:                                                  Saltwater
24:                                                She Is Love
25:                                               Burn for You
26:                                Dedicated To The One I Love
27:                                 Don't Cry for Me Argentina
28:                                                Blue Velvet
29:                                                Lay Me Down
30:                                                    Falling
31:                                        everything i wanted
32:                                    Like I'm Gonna Lose You
33:                                            Try to Remember
34:                              All of Me (Glee Cast Version)
35:                        The First Time Ever I Saw Your Face
36:                          Everybody's Got To Learn Sometime
37:                                            From a Distance
38:                                               Are You Sure
39:                                        Fast Car - Acoustic
40:                                       I Need to Be In Love
41:                                          The Power Of Love
42:                                           I Believe In You
43:                I Finally Found Someone (feat. Bryan Adams)
44:                                                She Is Love
45:                                                       July
46:                                                    Jealous
47:                                    Honey - 1991 - Remaster
48:                                           All I Ask Of You
49:                          You've Never Been This Far Before
50:                                           It's Oh So Quiet
51:                                     Stay with Me Till Dawn
52:                                      The Day You Went Away
53:               everytime we touch [Yanou's candlelight mix]
54:                                          Come Away With Me
55:                                     Anyone Who Had a Heart
56:                                              Say Something
57:                                       Angel Of The Morning
58:                                              Could've Been
59:                                      The Blower's Daughter
60:                                                       Mama
61:                                         You Are The Reason
62:                                                Lay Me Down
63:                                                True Colors
64:                                                   comethru
65:                                    The Very Thought of You
66:                                                Soldier Boy
67:                                            Nothing Like Us
68:                                         You Are The Reason
69:                                                  I'm Sorry
70:                                             God Only Knows
71:                                      when the party's over
72:                                     I Will Always Love You
73:                                              Say Something
74:                                     Have I Told You Lately
75:                                 Lonely (with benny blanco)
76:                                                      Maria
77:                                            Not In That Way
78:                                                Lay Me Down
79:                                      Popsicles And Icicles
80:                                      Make You Feel My Love
81:                                             Beautiful Lies
82:                   Roses Are Red (My Love) - Single Version
83:                                           Unchained Melody
84:                           Don't You Worry Child - Acoustic
85:                                         I Know Him So Well
86:                            High Sheriff of Calhoun Parrish
87:                                              Foolish Games
88:                                                   The Rose
                                                    track_name
                                     artist_name_s
                                            <char>
 1:                                   Neil Diamond
 2:                               Jasmine Thompson
 3:                         The Righteous Brothers
 4: Julie Covington, Andrew Lloyd Webber, Tim Rice
 5:                                 Connie Francis
 6:                                 The Civil Wars
 7:                                     Ed Sheeran
 8:                                Whitney Houston
 9:                                    Calum Scott
10:                                  Michael Bublé
11:                                    John Denver
12:                                    Norah Jones
13:                                    Norah Jones
14:                                    John Rowles
15:                                      Mr. Probz
16:                            The Everly Brothers
17:                                     Ed Sheeran
18:                                    Rick Astley
19:                          Fairground Attraction
20:                                          Birdy
21:                 Barbra Streisand, Neil Diamond
22:                                    Calum Scott
23:                                  Julian Lennon
24:                                      Parachute
25:                                   John Farnham
26:                                  The Shirelles
27:                                        Madonna
28:                                   Bobby Vinton
29:                         Sam Smith, John Legend
30:                                   Julee Cruise
31:                                  Billie Eilish
32:                               Jasmine Thompson
33:                                   Des O'Connor
34:                                      Glee Cast
35:                                 George Michael
36:                                     The Korgis
37:                                   Bette Midler
38:                                  Willie Nelson
39:                             Jonas Blue, Dakota
40:                                        Dami Im
41:                      Frankie Goes To Hollywood
42:                                   Don Williams
43:                  Barbra Streisand, Bryan Adams
44:                                      Parachute
45:                                     Noah Cyrus
46:                                       Labrinth
47:                                Bobby Goldsboro
48:                 Sarah Brightman, Cliff Richard
49:                                  Conway Twitty
50:                                          Björk
51:                                    Judie Tzuke
52:                                 Wendy Matthews
53:                                        Cascada
54:                                    Norah Jones
55:                                 Dionne Warwick
56:          A Great Big World, Christina Aguilera
57:                                   Juice Newton
58:              Tiffany, George Tobin, Bill Smith
59:                                    Damien Rice
60:                                 Connie Francis
61:                                    Calum Scott
62:                         Sam Smith, John Legend
63:                                   Cyndi Lauper
64:                                  Jeremy Zucker
65:                                  Michael Bublé
66:                                  The Shirelles
67:                                  Justin Bieber
68:                                    Calum Scott
69:                                    John Denver
70:                                  Michael Bublé
71:                                  Billie Eilish
72:                                Whitney Houston
73:          A Great Big World, Christina Aguilera
74:                                 Russell Watson
75:                    Justin Bieber, benny blanco
76:                                     P.J. Proby
77:                                      Sam Smith
78:                         Sam Smith, John Legend
79:                                   The Murmaids
80:                                          Adele
81:                                          Birdy
82:                                   Bobby Vinton
83:                         The Righteous Brothers
84:                                  Conor Maynard
85:                  Elaine Paige, Barbara Dickson
86:                                 Tony Joe White
87:                                          Jewel
88:                                   Bette Midler
                                     artist_name_s
                                                                                     album_name
                                                                                         <char>
 1:                                                                              Sweet Caroline
 2:                                                                                  Take Cover
 3:                                  The Very Best Of The Righteous Brothers - Unchained Melody
 4:                                                  Unmasked: The Platinum Collection (Deluxe)
 5:                                    The Very Best Of Connie Francis - Connie 21 Biggest Hits
 6:                                                                               Barton Hollow
 7: The Hobbit - The Desolation Of Smaug (Original Motion Picture Soundtrack / Special Edition)
 8:                                                   The Bodyguard - Original Soundtrack Album
 9:                                                                         Only Human (Deluxe)
10:                                                                      Nobody but Me (Deluxe)
11:                                                                               Higher Ground
12:                                                    Come Away With Me (Super Deluxe Edition)
13:                                                                           Come Away With Me
14:                                                                     True 60s Love (3CD Set)
15:                                                                      Nothing Really Matters
16:                                                                            It's Everly Time
17:                                                                                           +
18:                                                                  Whenever You Need Somebody
19:                                                               The First Of A Million Kisses
20:                                                                     Beautiful Lies (Deluxe)
21:                                                                                       Duets
22:                                                                           Dancing On My Own
23:                                                                               Help Yourself
24:                                                                                Losing Sleep
25:                                                                              Chain Reaction
26:                                                             Will You Still Love Me Tomorrow
27:                                         Evita: The Complete Motion Picture Music Soundtrack
28:                                                                                 Collections
29:                                                                                 Lay Me Down
30:                                                                     Floating Into The Night
31:                                                                         everything i wanted
32:                                                                     Like I'm Gonna Lose You
33:                                                                                     Anytime
34:                                          Glee: The Music, The Untitled Rachel Berry Project
35:                                                                 Songs From The Last Century
36:                                                Don't Look Back: The Very Best of The Korgis
37:                                                                         Some People's Lives
38:                                                  Willie Nelson: The Demos Project, Vol. One
39:                                                                         Fast Car (Acoustic)
40:                                                                          Classic Carpenters
41:                                                              Bang! (Here Comes a Supernova)
42:                                                               The Very Best Of Don Williams
43:                                    The Mirror Has Two Faces - Music From The Motion Picture
44:                                                                                Losing Sleep
45:                                                                       THE END OF EVERYTHING
46:                                                                                     Jealous
47:                                                         Honey - The Best of Bobby Goldsboro
48:                                                                          Private Collection
49:                                                                              25 Number Ones
50:                                                                                        Post
51:                                                                       Welcome to the Cruise
52:                                                                                        Lily
53:                                                                           Acoustic Sessions
54:                                                    Come Away With Me (Super Deluxe Edition)
55:                                                                      Anyone Who Had a Heart
56:                                     Is There Anybody Out There? - Track by Track Commentary
57:                                                                Juice Newton's Greatest Hits
58:                                                                                     Tiffany
59:                                                                       The Blower's Daughter
60:                                                                     Sings Italian Favorites
61:                                                                         Only Human (Deluxe)
62:                                                                                 Lay Me Down
63:                                                                                 True Colors
64:                                                                                     summer,
65:                                                                      Nobody but Me (Deluxe)
66:                                                                            20 Greatest Hits
67:                                                                            Believe Acoustic
68:                                                                         Only Human (Deluxe)
69:                                                                                    Windsong
70:                                                                      Nobody but Me (Deluxe)
71:                                                                       when the party's over
72:                                         I Will Always Love You: The Best Of Whitney Houston
73:                                                                 Is There Anybody Out There?
74:                                                      Popera - Essential Classical Crossover
75:                                                                  Lonely (with benny blanco)
76:                                                                            In Town / Enigma
77:                                               In The Lonely Hour (Drowning Shadows Edition)
78:                                               In The Lonely Hour (Drowning Shadows Edition)
79:                                             Popsicles and Icicles: the Best of the Murmaids
80:                                                                                          19
81:                                                                     Beautiful Lies (Deluxe)
82:                                                                    The Best Of Bobby Vinton
83:                                                                        Just Once In My Life
84:                                                                                      Animal
85:                                                                                  Love Hurts
86:                                   The Best Of Tony Joe White Featuring ""Polk Salad Annie""
87:                                                                               Pieces Of You
88:                                                                                    The Rose
                                                                                     album_name
            album_artist_name_s album_release_date disc_number track_number
                         <char>             <char>       <int>        <int>
 1:                Neil Diamond               1969           1           13
 2:            Jasmine Thompson         2014-12-09           1            3
 3:      The Righteous Brothers               1990           1            2
 4:         Andrew Lloyd Webber         2018-03-16           1           10
 5:              Connie Francis         1987-01-12           1           16
 6:              The Civil Wars         2012-03-05           1            5
 7:                Howard Shore         2013-01-01           1           28
 8:             Whitney Houston         1992-11-17           1            1
 9:                 Calum Scott         2018-03-09           1            7
10:               Michael Bublé         2016-10-21           1           10
11:                 John Denver               1988           1            8
12:                 Norah Jones         2002-02-26           1            7
13:                 Norah Jones         2002-02-26           1            1
14:             Various Artists         2006-01-01           1            2
15:                   Mr. Probz         2014-09-27           1            1
16:         The Everly Brothers               1960           1            1
17:                  Ed Sheeran         2011-09-09           1           11
18:                 Rick Astley         1987-11-12           1           10
19:       Fairground Attraction               1988           1            2
20:                       Birdy         2016-03-25           1            6
21:            Barbra Streisand         2002-11-26           1            3
22:                 Calum Scott         2016-06-03           1            1
23:               Julian Lennon         1991-01-01           1            2
24:                   Parachute         2009-01-01           1            5
25:                John Farnham         1990-09-24           1            3
26:               The Shirelles               2005           1            2
27:                     Madonna         1996-10-25           1           16
28:                Bobby Vinton         2006-01-31           1            1
29:                   Sam Smith         2015-03-09           1            1
30:                Julee Cruise         1989-09-12           1            2
31:               Billie Eilish         2019-11-13           1            1
32:            Jasmine Thompson         2015-10-09           1            1
33:                Des O'Connor               1990           1           21
34:                   Glee Cast         2014-05-13           1            2
35:              George Michael         1999-12-06           1            5
36:                  The Korgis         2003-08-05           1           11
37:                Bette Midler               1990           1            7
38:               Willie Nelson         2016-09-16           1            6
39:                  Jonas Blue         2016-02-01           1            1
40:                     Dami Im         2016-04-22           1            9
41:   Frankie Goes To Hollywood         1985-01-01           1            6
42:                Don Williams         1992-01-21           1           12
43:            Barbra Streisand         1996-10-15           1           23
44:                   Parachute         2009-01-01           1            5
45:                  Noah Cyrus         2020-05-15           1            6
46:                    Labrinth         2014-11-21           1            1
47:             Bobby Goldsboro               1991           1           15
48:               Cliff Richard         1988-11-07           1            3
49:               Conway Twitty         2004-01-01           1            8
50:                       Björk         1995-06-13           1            4
51:                 Judie Tzuke         1979-05-27           1           10
52:              Wendy Matthews               1992           1            6
53:                     Cascada         2013-11-01           1            6
54:                 Norah Jones         2002-02-26           1            5
55:              Dionne Warwick               1964           1            1
56:           A Great Big World         2014-01-13           1           25
57:                Juice Newton         1988-10-19           1            1
58:                     Tiffany         1987-01-01           1           10
59:                 Damien Rice               2002           1            1
60:              Connie Francis         1959-01-01           1            9
61:                 Calum Scott         2018-03-09           1            4
62:                   Sam Smith         2015-03-09           1            1
63:                Cyndi Lauper         1986-10-14           1            4
64:               Jeremy Zucker         2018-09-28           1            1
65:               Michael Bublé         2016-10-21           1            6
66:               The Shirelles               2005           1            6
67:               Justin Bieber         2013-01-01           1           11
68:                 Calum Scott         2018-03-09           1            4
69:                 John Denver            1975-09           1            9
70:               Michael Bublé         2016-10-21           1           13
71:               Billie Eilish         2018-10-17           1            1
72:             Whitney Houston         2012-11-12           1           11
73:           A Great Big World         2014-01-20           1           13
74:             Various Artists         2014-12-09           1           11
75: Justin Bieber, benny blanco         2020-10-16           1            1
76:                  P.J. Proby               1994           1           11
77:                   Sam Smith         2015-11-06           1            9
78:                   Sam Smith         2015-11-06           1           23
79:                The Murmaids         2011-01-04           1           13
80:                       Adele         2008-01-28           1            9
81:                       Birdy         2016-03-25           1           14
82:                Bobby Vinton               1962           1            1
83:      The Righteous Brothers         1965-04-04           1            3
84:               Conor Maynard         2013-01-18           1            5
85:                Elaine Paige               1985           1           11
86:              Tony Joe White               1972           1            7
87:                       Jewel               1995           1            4
88:                Bette Midler               1979           1           12
            album_artist_name_s album_release_date disc_number track_number
    track_duration_ms explicit popularity         isrc                 added_by
                <int>   <lgcl>      <int>       <char>                   <char>
 1:            203573    FALSE          0 USMC16991138 spotify:user:bradnumber1
 2:            195669    FALSE         29 USAT21404350 spotify:user:bradnumber1
 3:            215840    FALSE          0 USPG16590023 spotify:user:bradnumber1
 4:            324720    FALSE         37 USMC10111984 spotify:user:bradnumber1
 5:            156893    FALSE          0 USF096100270 spotify:user:bradnumber1
 6:            219466    FALSE         48 USW5Q1100005 spotify:user:bradnumber1
 7:            300840    FALSE         74 USNLR1300728 spotify:user:bradnumber1
 8:            271093    FALSE         81 USAR19200110 spotify:user:bradnumber1
 9:            260285    FALSE         83 UK6KW1500205 spotify:user:bradnumber1
10:            259959    FALSE         33 USRE11600458 spotify:user:bradnumber1
11:            201293    FALSE          0 USA370529707 spotify:user:bradnumber1
12:            154800    FALSE         73 USBN20100532 spotify:user:bradnumber1
13:            186146    FALSE          6 USBN20100529 spotify:user:bradnumber1
14:            167426    FALSE          0 USMC10201342 spotify:user:bradnumber1
15:            222041    FALSE          0 NLB8R1400010 spotify:user:bradnumber1
16:            154400    FALSE         35 USWB10704350 spotify:user:bradnumber1
17:            280853    FALSE         71 GBAHS1100208 spotify:user:bradnumber1
18:            183026    FALSE          0 GBARL9300132 spotify:user:bradnumber1
19:            216573    FALSE         56 GBARL8800011 spotify:user:bradnumber1
20:            227160    FALSE         30 GBAHS1600024 spotify:user:bradnumber1
21:            204200    FALSE         41 USSM10020874 spotify:user:bradnumber1
22:            260004    FALSE          0 UK6KW1500205 spotify:user:bradnumber1
23:            247093    FALSE         45 GBAAA9100043 spotify:user:bradnumber1
24:            146066    FALSE         59 USUM70964234 spotify:user:bradnumber1
25:            212933    FALSE         47 AUBM09041013 spotify:user:bradnumber1
26:            124186    FALSE          0 USACU0500001 spotify:user:bradnumber1
27:            335733    FALSE         58 USWB19600674 spotify:user:bradnumber1
28:            167213    FALSE         47 USSM19601971 spotify:user:bradnumber1
29:            219662    FALSE          0 GBUM71500850 spotify:user:bradnumber1
30:            321853    FALSE         51 USWB10100198 spotify:user:bradnumber1
31:            245425    FALSE         87 USUM71922577 spotify:user:bradnumber1
32:            232338    FALSE         69 USAT21502787 spotify:user:bradnumber1
33:            204106    FALSE         17 GBAYE6800205 spotify:user:bradnumber1
34:            270933    FALSE         39 USQX91401043 spotify:user:bradnumber1
35:            319440    FALSE         52 GBDFN9900005 spotify:user:bradnumber1
36:            258665    FALSE         54 GBAJE8000325 spotify:user:bradnumber1
37:            276346    FALSE         56 USAT20000391 spotify:user:bradnumber1
38:            127454    FALSE         36 USJGN1614363 spotify:user:bradnumber1
39:            217864    FALSE         65 GBUM71600355 spotify:user:bradnumber1
40:            235986    FALSE         21 AUBM01600046 spotify:user:bradnumber1
41:            328864    FALSE          0 GBAHW9900034 spotify:user:bradnumber1
42:            245226    FALSE         32 USMC18009838 spotify:user:bradnumber1
43:            221973    FALSE         67 USSM19603517 spotify:user:bradnumber1
44:            146066    FALSE          0 USUM70964234 spotify:user:bradnumber1
45:            156106    FALSE         82 USQX91901092 spotify:user:bradnumber1
46:            287693    FALSE          1 GBHMU1400291 spotify:user:bradnumber1
47:            239066    FALSE          0 USCN19100052 spotify:user:bradnumber1
48:            252333    FALSE         28 GBALG8600002 spotify:user:bradnumber1
49:            181932    FALSE         45 USMC17301546 spotify:user:bradnumber1
50:            218773    FALSE          0 GBAKY9500010 spotify:user:bradnumber1
51:            235266    FALSE          0 GBKPL1792328 spotify:user:bradnumber1
52:            282866    FALSE         47 AUBM09320306 spotify:user:bradnumber1
53:            195773    FALSE          0 DEZ620500093 spotify:user:bradnumber1
54:            198226    FALSE         76 USBN20100889 spotify:user:bradnumber1
55:            184226    FALSE         48 USWSP0000010 spotify:user:bradnumber1
56:            229400    FALSE         72 USSM11306713 spotify:user:bradnumber1
57:            254000    FALSE         59 USCN18100023 spotify:user:bradnumber1
58:            212693    FALSE         54 USMC10000688 spotify:user:bradnumber1
59:            288466    FALSE         46 IEABD0100003 spotify:user:bradnumber1
60:            237866    FALSE          0 USPR35912029 spotify:user:bradnumber1
61:            204326    FALSE          0 USUM71710315 spotify:user:bradnumber1
62:            219662    FALSE          0 GBUM71500850 spotify:user:bradnumber1
63:            227600    FALSE         75 USSM18600632 spotify:user:bradnumber1
64:            181613    FALSE         80 USUM71813455 spotify:user:bradnumber1
65:            211613    FALSE         37 USRE11600455 spotify:user:bradnumber1
66:            162013    FALSE          0 USACU0500013 spotify:user:bradnumber1
67:            199800    FALSE         62 USUM71300154 spotify:user:bradnumber1
68:            204326    FALSE         82 USUM71710315 spotify:user:bradnumber1
69:            211773    FALSE         53 USRC11100358 spotify:user:bradnumber1
70:            255400    FALSE         36 USRE11600463 spotify:user:bradnumber1
71:            199931    FALSE          0 USUM71815958 spotify:user:bradnumber1
72:            270760    FALSE          5 USAR19200110 spotify:user:bradnumber1
73:            229400    FALSE         76 USSM11306713 spotify:user:bradnumber1
74:            274480    FALSE          0 GBBBA0742080 spotify:user:bradnumber1
75:            149297    FALSE         52 USUM72019037 spotify:user:bradnumber1
76:            217573    FALSE          1 GBVVQ1700070 spotify:user:bradnumber1
77:            172452    FALSE          0 GBUM71308838 spotify:user:bradnumber1
78:            219535    FALSE          0 GBUM71500850 spotify:user:bradnumber1
79:            155400    FALSE          3 USXTN1038610 spotify:user:bradnumber1
80:            212040    FALSE          1 GBBKS0700586 spotify:user:bradnumber1
81:            170720    FALSE         30 GBAHS1600032 spotify:user:bradnumber1
82:            158933    FALSE         43 USSM10404744 spotify:user:bradnumber1
83:            218013    FALSE         78 USPG19090023 spotify:user:bradnumber1
84:            185106    FALSE         40 GBAYE1202445 spotify:user:bradnumber1
85:            257106    FALSE         53 GBAHT9500260 spotify:user:bradnumber1
86:            233400    FALSE         26 USWB17000003 spotify:user:bradnumber1
87:            340666    FALSE          0 USAT29400014 spotify:user:bradnumber1
88:            221373    FALSE         68 USAT29901582 spotify:user:bradnumber1
    track_duration_ms explicit popularity         isrc                 added_by
               added_at
                 <POSc>
 1: 2021-08-08 09:27:38
 2: 2021-08-08 09:26:31
 3: 2021-08-08 09:27:55
 4: 2021-08-08 09:26:31
 5: 2021-08-08 09:26:31
 6: 2021-08-08 09:26:31
 7: 2021-08-08 09:26:31
 8: 2021-08-08 09:26:31
 9: 2021-08-08 09:26:31
10: 2021-08-08 09:26:31
11: 2021-08-08 09:26:31
12: 2022-12-21 10:18:04
13: 2021-08-08 09:26:31
14: 2021-08-08 09:26:31
15: 2021-08-08 09:26:31
16: 2021-08-08 09:26:31
17: 2021-08-08 09:26:31
18: 2021-08-08 09:26:31
19: 2021-08-08 09:26:31
20: 2021-08-08 09:26:31
21: 2021-08-08 09:26:31
22: 2021-08-08 09:26:31
23: 2021-08-08 09:26:31
24: 2021-08-08 09:26:31
25: 2021-08-08 09:26:31
26: 2021-08-08 09:26:31
27: 2021-08-08 09:26:31
28: 2021-08-08 09:26:31
29: 2021-08-08 09:26:31
30: 2021-08-08 09:26:31
31: 2021-08-08 09:26:31
32: 2021-08-08 09:26:31
33: 2021-08-08 09:26:31
34: 2021-08-08 09:26:31
35: 2021-08-08 09:26:31
36: 2021-08-08 09:26:31
37: 2021-08-08 09:26:31
38: 2022-09-19 23:21:22
39: 2021-08-08 09:26:31
40: 2021-08-08 09:26:31
41: 2021-08-08 09:26:31
42: 2021-08-08 09:26:31
43: 2021-08-08 09:26:31
44: 2021-08-08 09:26:31
45: 2021-08-08 09:26:31
46: 2021-08-08 09:26:31
47: 2021-08-08 09:26:31
48: 2021-08-08 09:26:31
49: 2021-08-08 09:26:31
50: 2021-08-08 09:26:31
51: 2021-08-08 09:26:31
52: 2021-08-08 09:26:31
53: 2021-08-08 09:26:31
54: 2022-12-21 10:17:59
55: 2021-08-08 09:26:31
56: 2021-08-08 09:26:31
57: 2021-08-08 09:26:31
58: 2021-08-08 09:26:31
59: 2021-08-08 09:26:31
60: 2021-08-08 09:26:31
61: 2021-08-08 09:26:31
62: 2021-08-08 09:26:31
63: 2021-08-08 09:26:31
64: 2021-08-08 09:26:31
65: 2021-08-08 09:26:31
66: 2021-08-08 09:26:31
67: 2021-08-08 09:26:31
68: 2021-08-08 09:26:31
69: 2021-08-08 09:26:31
70: 2021-08-08 09:26:31
71: 2021-08-08 09:26:31
72: 2021-08-08 09:26:31
73: 2021-08-08 09:26:31
74: 2021-08-08 09:26:31
75: 2021-08-08 09:26:31
76: 2021-08-08 09:26:31
77: 2021-08-08 09:26:31
78: 2021-08-08 09:26:31
79: 2021-08-08 09:26:31
80: 2021-08-08 09:26:31
81: 2021-08-08 09:26:31
82: 2021-08-08 09:26:31
83: 2021-08-08 09:26:31
84: 2021-08-08 09:26:31
85: 2021-08-08 09:26:31
86: 2021-08-08 09:26:31
87: 2021-08-08 09:26:31
88: 2021-08-08 09:26:31
               added_at
                                                                                                                                                    artist_genres
                                                                                                                                                           <char>
 1:                                                adult standards,brill building pop,folk rock,heartland rock,mellow gold,singer-songwriter,soft rock,yacht rock
 2:                                                                                                                                                     viral pop
 3:                                                                                         adult standards,brill building pop,folk rock,rock-and-roll,rockabilly
 4:                                                                                                                              classic uk pop,broadway,west end
 5:                                                                                    adult standards,brill building pop,easy listening,rock-and-roll,rockabilly
 6:                                                                                             acoustic pop,indie folk,neo mellow,new americana,stomp and holler
 7:                                                                                                                              pop,singer-songwriter pop,uk pop
 8:                                                                                                                                                     dance pop
 9:                                                                                                                                                           pop
10:                                                                                                                  adult standards,canadian pop,jazz pop,lounge
11:                                                                                    classic country pop,folk,folk rock,mellow gold,singer-songwriter,soft rock
12:                                                                                                                   contemporary vocal jazz,jazz pop,vocal jazz
13:                                                                                                                   contemporary vocal jazz,jazz pop,vocal jazz
14:                                                                                                                                                classic nz pop
15:                                                                                                                                                     pop dance
16:                                                                                   adult standards,folk rock,mellow gold,rock-and-roll,rockabilly,sunshine pop
17:                                                                                                                              pop,singer-songwriter pop,uk pop
18:                                                                                                     new romantic,new wave pop,soft rock,sophisti-pop,synthpop
19:                                                                                                                                                  new wave pop
20:                                                                                                                                             neo mellow,uk pop
21:                   adult standards,operatic pop,adult standards,brill building pop,folk rock,heartland rock,mellow gold,singer-songwriter,soft rock,yacht rock
22:                                                                                                                                                           pop
23:                                                                                                                                       beatlesque,new wave pop
24:                                                                                acoustic pop,charlottesville indie,neo mellow,neon pop punk,pop rock,viral pop
25:                                                                                                                                australian pop,australian rock
26:                                                                                                          classic girl group,doo-wop,motown,rock-and-roll,soul
27:                                                                                                                                                 dance pop,pop
28:                                                                                 adult standards,bubblegum pop,doo-wop,easy listening,rock-and-roll,rockabilly
29:                                                                                                           pop,uk pop,neo soul,pop,pop soul,urban contemporary
30:                                                                                                                                                     dream pop
31:                                                                                                                                        art pop,electropop,pop
32:                                                                                                                                                     viral pop
33:                                                                                                                                     classic uk pop,merseybeat
34:                                                                                                                                       glee club,post-teen pop
35:                                                                                                                                                  new wave pop
36:                                                                                                                                                classic uk pop
37:                                                                                                                        adult standards,new wave pop,soft rock
38:                                               classic country pop,classic texas country,country,country rock,nashville sound,outlaw country,singer-songwriter
39:                                                                                                                         pop,pop dance,tropical house,uk dance
40:                                                                                                             australian pop,australian talent show,talent show
41:                                                                                                 dance rock,hi-nrg,new romantic,new wave,new wave pop,synthpop
42:                                                                                                                                   classic country pop,country
43:                               adult standards,operatic pop,canadian pop,canadian singer-songwriter,classic canadian rock,heartland rock,mellow gold,soft rock
44:                                                                                acoustic pop,charlottesville indie,neo mellow,neon pop punk,pop rock,viral pop
45:                                                                                                                                                     alt z,pop
46:                                                                                                                                           indie poptimism,pop
47:                                                                                         adult standards,bubblegum pop,easy listening,merseybeat,rock-and-roll
48:                                                                                                                    operatic pop,adult standards,rock-and-roll
49:                                                                                                     arkansas country,classic country pop,country,country rock
50: art pop,electronica,experimental pop,experimental vocal,icelandic experimental,icelandic pop,icelandic singer-songwriter,metropopolis,permanent wave,trip hop
51:                                                                                                                                                classic uk pop
52:                                                                                                                                australian pop,australian rock
53:                                                                                                eurodance,europop,german techno,melbourne bounce international
54:                                                                                                                   contemporary vocal jazz,jazz pop,vocal jazz
55:                                                                                                adult standards,brill building pop,disco,quiet storm,soft rock
56:                                                                                                        neo mellow,piano rock,pop rock,viral pop,dance pop,pop
57:                                                                                                                    classic country pop,country dawn,soft rock
58:                                                                                                                                        new wave pop,soft rock
59:                                                                                  acoustic pop,irish rock,irish singer-songwriter,neo mellow,singer-songwriter
60:                                                                                    adult standards,brill building pop,easy listening,rock-and-roll,rockabilly
61:                                                                                                                                                           pop
62:                                                                                                           pop,uk pop,neo soul,pop,pop soul,urban contemporary
63:                                                                                                               dance pop,new wave pop,permanent wave,soft rock
64:                                                                                                                                          alt z,electropop,pop
65:                                                                                                                  adult standards,canadian pop,jazz pop,lounge
66:                                                                                                          classic girl group,doo-wop,motown,rock-and-roll,soul
67:                                                                                                                                              canadian pop,pop
68:                                                                                                                                                           pop
69:                                                                                    classic country pop,folk,folk rock,mellow gold,singer-songwriter,soft rock
70:                                                                                                                  adult standards,canadian pop,jazz pop,lounge
71:                                                                                                                                        art pop,electropop,pop
72:                                                                                                                                                     dance pop
73:                                                                                                        neo mellow,piano rock,pop rock,viral pop,dance pop,pop
74:                                                                                                                                                  operatic pop
75:                                                                                                                                          canadian pop,pop,pop
76:                                                                                                                       classic uk pop,merseybeat,rock-and-roll
77:                                                                                                                                                    pop,uk pop
78:                                                                                                           pop,uk pop,neo soul,pop,pop soul,urban contemporary
79:                                                                                                                                            classic girl group
80:                                                                                                                              british soul,pop,pop soul,uk pop
81:                                                                                                                                             neo mellow,uk pop
82:                                                                                 adult standards,bubblegum pop,doo-wop,easy listening,rock-and-roll,rockabilly
83:                                                                                         adult standards,brill building pop,folk rock,rock-and-roll,rockabilly
84:                                                                                                                                post-teen pop,uk pop,viral pop
85:                                                                                                                    classic uk pop,operatic pop,classic uk pop
86:                                                                                                              louisiana blues,swamp blues,swamp pop,swamp rock
87:                                                                                        alaska indie,ectofolk,lilith,permanent wave,pop rock,singer-songwriter
88:                                                                                                                        adult standards,new wave pop,soft rock
                                                                                                                                                    artist_genres
    danceability energy   key loudness  mode speechiness acousticness
           <num>  <num> <int>    <num> <int>       <num>        <num>
 1:        0.529 0.1270    11  -16.066     1      0.0274        0.611
 2:        0.404 0.1850     0  -11.889     1      0.0512        0.891
 3:        0.376 0.1990     0  -16.679     1      0.0288        0.535
 4:        0.235 0.2130     1   -8.764     1      0.0339        0.828
 5:        0.256 0.1630     0   -9.856     1      0.0297        0.754
 6:        0.284 0.1710     1  -12.762     1      0.0285        0.788
 7:        0.581 0.0549    10  -20.514     0      0.0397        0.559
 8:        0.332 0.2140     4  -12.518     1      0.0349        0.845
 9:        0.681 0.1740     1   -8.745     1      0.0315        0.837
10:        0.163 0.1720     9  -10.672     1      0.0312        0.697
11:        0.270 0.1140     0  -19.563     1      0.0341        0.869
12:        0.429 0.1800    10  -10.694     1      0.0551        0.864
13:        0.732 0.1980     5  -11.775     1      0.0280        0.883
14:        0.370 0.2280     5  -14.436     1      0.0340        0.438
15:        0.404 0.2250     4   -8.829     1      0.0363        0.888
16:        0.545 0.1970     4  -16.743     1      0.0285        0.646
17:        0.589 0.2270     2  -16.670     1      0.0498        0.640
18:        0.196 0.1230     1  -20.322     1      0.0344        0.760
19:        0.579 0.2030     9  -15.216     0      0.0657        0.292
20:        0.558 0.1890     7  -12.408     1      0.0355        0.950
21:        0.192 0.2120     0  -13.018     1      0.0356        0.889
22:        0.608 0.1740     1   -8.796     1      0.0332        0.851
23:        0.199 0.2150     9  -15.643     1      0.0285        0.619
24:        0.629 0.1740     6   -9.697     1      0.1410        0.616
25:        0.547 0.1320     8  -15.204     0      0.0303        0.896
26:        0.459 0.1910    10  -11.901     1      0.0341        0.800
27:        0.323 0.1490    11  -13.906     1      0.0339        0.898
28:        0.380 0.2000    10  -10.825     1      0.0296        0.789
29:        0.463 0.1980     4  -11.003     1      0.0387        0.915
30:        0.192 0.1380     5  -17.135     1      0.0315        0.892
31:        0.704 0.2250     6  -14.454     0      0.0994        0.902
32:        0.398 0.1740     0  -11.160     1      0.0364        0.958
33:        0.469 0.1830     0  -15.102     1      0.0323        0.902
34:        0.456 0.2430     8   -8.664     1      0.0350        0.885
35:        0.334 0.0736     1  -19.293     1      0.0329        0.924
36:        0.369 0.2380     1  -14.994     0      0.0269        0.554
37:        0.536 0.2420     7  -11.716     1      0.0277        0.674
38:        0.586 0.0205    10  -15.556     1      0.0559        0.961
39:        0.475 0.2370     9   -9.923     1      0.0342        0.865
40:        0.416 0.1520    10   -9.037     1      0.0312        0.961
41:        0.464 0.2300     5  -13.791     0      0.0325        0.349
42:        0.695 0.1680     7  -23.092     1      0.0397        0.890
43:        0.568 0.2240     6  -15.069     1      0.0296        0.677
44:        0.629 0.1740     6   -9.697     1      0.1410        0.616
45:        0.708 0.1860     9   -8.953     0      0.0420        0.868
46:        0.439 0.1530     1   -8.950     1      0.0479        0.874
47:        0.500 0.1890     7  -17.563     1      0.0307        0.210
48:        0.209 0.2470     1  -15.144     1      0.0357        0.938
49:        0.469 0.2350    10  -14.399     1      0.0336        0.694
50:        0.459 0.1270     3  -14.191     1      0.0544        0.618
51:        0.320 0.2000     2  -14.917     0      0.0326        0.834
52:        0.628 0.2030     4  -13.713     1      0.0340        0.867
53:        0.445 0.1730     5  -11.068     0      0.0356        0.928
54:        0.436 0.1410     0  -13.271     1      0.0308        0.902
55:        0.505 0.0477     8  -23.032     1      0.0278        0.910
56:        0.407 0.1470     2   -8.822     1      0.0355        0.857
57:        0.456 0.2330     8  -12.634     1      0.0255        0.433
58:        0.474 0.2380     1  -15.595     1      0.0271        0.554
59:        0.334 0.1920     4  -13.983     1      0.0337        0.135
60:        0.177 0.2170     0  -11.120     1      0.0341        0.889
61:        0.329 0.2340    10   -7.725     1      0.0303        0.913
62:        0.469 0.1960     4  -11.112     1      0.0382        0.922
63:        0.397 0.2070     0  -13.155     1      0.0331        0.701
64:        0.795 0.1780     0  -11.991     1      0.0574        0.607
65:        0.255 0.1310     5  -10.896     1      0.0323        0.713
66:        0.569 0.1980    10  -15.481     1      0.0265        0.754
67:        0.546 0.1550     0  -14.378     1      0.0428        0.987
68:        0.329 0.2350    10   -7.699     1      0.0303        0.918
69:        0.447 0.2360     7  -15.258     1      0.0313        0.891
70:        0.305 0.0307     6  -15.627     1      0.0409        0.971
71:        0.498 0.1040     1  -14.080     0      0.0621        0.979
72:        0.311 0.2160     4  -12.555     1      0.0355        0.841
73:        0.407 0.1470     2   -8.822     1      0.0355        0.857
74:        0.399 0.2060     5  -12.763     1      0.0309        0.786
75:        0.631 0.2260    11   -7.257     0      0.0396        0.879
76:        0.214 0.2230     2  -13.371     1      0.0307        0.915
77:        0.392 0.1500     2  -12.494     1      0.0322        0.940
78:        0.468 0.2050     4  -11.014     1      0.0412        0.921
79:        0.641 0.2090     3  -15.404     1      0.0354        0.597
80:        0.559 0.1720    10  -10.636     1      0.0291        0.907
81:        0.528 0.1330     4  -12.725     0      0.0633        0.918
82:        0.515 0.2180     5  -10.071     1      0.0287        0.828
83:        0.339 0.2080     0  -16.725     1      0.0308        0.396
84:        0.609 0.2310     0   -9.709     1      0.0383        0.845
85:        0.423 0.2110    10  -12.268     1      0.0287        0.820
86:        0.691 0.2340     2  -17.215     1      0.0357        0.689
87:        0.298 0.0735     5  -16.472     1      0.0378        0.944
88:        0.347 0.2280     0   -9.667     1      0.0296        0.901
    danceability energy   key loudness  mode speechiness acousticness
    instrumentalness liveness valence   tempo time_signature album_genres
               <num>    <num>   <num>   <num>          <int>       <lgcl>
 1:         1.09e-04   0.2370  0.5780  63.050              4           NA
 2:         0.00e+00   0.1030  0.1470  75.342              3           NA
 3:         0.00e+00   0.5980  0.2470  98.970              3           NA
 4:         5.07e-05   0.1130  0.1530  70.075              4           NA
 5:         0.00e+00   0.1350  0.2610  83.139              4           NA
 6:         7.03e-05   0.1030  0.1920 153.948              4           NA
 7:         0.00e+00   0.0718  0.2340 152.037              4           NA
 8:         5.62e-06   0.0839  0.1100  67.531              4           NA
 9:         3.35e-05   0.0983  0.2310 112.672              4           NA
10:         6.88e-04   0.1610  0.1070  55.305              4           NA
11:         2.91e-06   0.1300  0.4370  90.493              4           NA
12:         4.40e-06   0.1040  0.4850 170.645              3           NA
13:         1.10e-05   0.0659  0.6180  88.174              4           NA
14:         4.82e-06   0.1120  0.2840  81.223              4           NA
15:         0.00e+00   0.1110  0.2750 135.075              4           NA
16:         0.00e+00   0.2910  0.3380 102.229              4           NA
17:         4.69e-03   0.0248  0.1820  74.993              4           NA
18:         1.22e-02   0.0977  0.1420  74.448              4           NA
19:         0.00e+00   0.0866  0.6020 138.798              4           NA
20:         2.62e-05   0.1090  0.1500 123.635              4           NA
21:         6.48e-05   0.1620  0.2120  86.984              3           NA
22:         1.92e-05   0.0855  0.1930 112.175              4           NA
23:         1.79e-06   0.1120  0.1180  67.958              4           NA
24:         0.00e+00   0.1180  0.3050 134.295              1           NA
25:         0.00e+00   0.0981  0.3300  97.136              4           NA
26:         0.00e+00   0.1640  0.5370  80.351              4           NA
27:         4.20e-06   0.0990  0.0788 105.033              5           NA
28:         1.45e-06   0.1760  0.2410  80.188              4           NA
29:         0.00e+00   0.1060  0.3690 123.630              4           NA
30:         5.53e-01   0.1140  0.0757 142.187              4           NA
31:         6.57e-01   0.1060  0.2430 120.006              4           NA
32:         4.16e-06   0.1580  0.1530 172.152              3           NA
33:         1.04e-01   0.1050  0.1820  93.086              3           NA
34:         0.00e+00   0.1120  0.4920 125.983              4           NA
35:         1.70e-01   0.1120  0.1200 132.360              4           NA
36:         4.25e-02   0.1250  0.0578  73.899              4           NA
37:         0.00e+00   0.3310  0.3310 137.989              4           NA
38:         1.91e-06   0.1100  0.2530  94.463              4           NA
39:         0.00e+00   0.0881  0.5950 103.045              4           NA
40:         1.22e-04   0.1210  0.0652 129.216              4           NA
41:         2.84e-06   0.5390  0.1140 123.108              4           NA
42:         2.63e-02   0.1210  0.5570 117.946              3           NA
43:         0.00e+00   0.1270  0.0709 138.964              4           NA
44:         0.00e+00   0.1180  0.3050 134.297              1           NA
45:         0.00e+00   0.0779  0.3220  72.541              4           NA
46:         0.00e+00   0.1070  0.1040 116.760              3           NA
47:         3.08e-05   0.1290  0.5870  93.259              4           NA
48:         8.34e-04   0.1100  0.2040  82.354              4           NA
49:         1.53e-01   0.0962  0.5200 138.522              4           NA
50:         0.00e+00   0.0708  0.2340 128.098              3           NA
51:         1.93e-03   0.1380  0.0896 129.936              4           NA
52:         1.65e-06   0.0892  0.2930 105.675              4           NA
53:         0.00e+00   0.2430  0.3050 113.882              4           NA
54:         2.81e-06   0.1260  0.1460  76.640              3           NA
55:         2.61e-06   0.0675  0.3090  78.856              3           NA
56:         2.89e-06   0.0913  0.0765 141.284              3           NA
57:         6.42e-05   0.0538  0.4240  75.174              4           NA
58:         3.95e-06   0.1070  0.1370  99.005              3           NA
59:         9.77e-05   0.4270  0.0775 133.198              4           NA
60:         5.57e-05   0.3460  0.1100  81.316              3           NA
61:         0.00e+00   0.1320  0.1990 170.466              3           NA
62:         0.00e+00   0.1050  0.3430 123.072              4           NA
63:         3.07e-05   0.1160  0.2680 171.282              4           NA
64:         0.00e+00   0.6230  0.6080  93.982              4           NA
65:         1.02e-03   0.1070  0.1100 173.134              3           NA
66:         2.00e-04   0.3310  0.6220  97.595              4           NA
67:         6.02e-05   0.1800  0.5120  72.331              4           NA
68:         0.00e+00   0.1370  0.2200 171.006              3           NA
69:         1.51e-03   0.2010  0.5270 127.596              4           NA
70:         3.36e-01   0.0985  0.2820  75.427              4           NA
71:         7.86e-05   0.0895  0.2050 124.001              3           NA
72:         5.31e-06   0.0862  0.1040 134.051              4           NA
73:         2.89e-06   0.0913  0.0765 141.284              3           NA
74:         0.00e+00   0.0948  0.1170 136.713              4           NA
75:         0.00e+00   0.1150  0.0765  79.968              4           NA
76:         0.00e+00   0.1360  0.1810 100.065              3           NA
77:         0.00e+00   0.1160  0.2960 144.268              3           NA
78:         0.00e+00   0.1070  0.3250 125.343              4           NA
79:         0.00e+00   0.1270  0.6660 124.013              4           NA
80:         3.83e-04   0.1050  0.0955  77.025              4           NA
81:         0.00e+00   0.3160  0.3010  85.654              4           NA
82:         0.00e+00   0.3020  0.5340 102.997              4           NA
83:         5.19e-04   0.1800  0.2880  98.540              3           NA
84:         0.00e+00   0.2700  0.3540 119.785              4           NA
85:         0.00e+00   0.0894  0.1310 138.610              4           NA
86:         3.46e-02   0.1120  0.5280  88.559              4           NA
87:         4.01e-04   0.0976  0.1740 131.045              4           NA
88:         0.00e+00   0.3800  0.1840 133.574              4           NA
    instrumentalness liveness valence   tempo time_signature album_genres
                                                         label
                                                        <char>
 1:                                      Universal Music Group
 2:                                           Atlantic Records
 3:                                                    Polydor
 4:                            UMC (Universal Music Catalogue)
 5:                                                    Polydor
 6:                                                   Columbia
 7:                                                Decca (UMO)
 8:                                                     Arista
 9:                                     Capitol Records (US1A)
10:                                                    Reprise
11:                                       Windstar Productions
12:                                         CM BLUE NOTE (A92)
13:                                          Blue Note Records
14:                                            Universal Music
15:                                       Left Lane Recordings
16:                                       Rhino/Warner Records
17:                                        Atlantic Records UK
18:                                              Sony Music CG
19:                                          RCA Records Label
20:                                        Atlantic Records UK
21:                                            NITRON concepts
22:                                      Universal Music Group
23:                                                     One Up
24:                                            Mercury Records
25:                                                  BMG Music
26:                                              Gusto Records
27:                                             Warner Records
28:                               Sony BMG Music Entertainment
29:                                                    UMG-EMI
30:                                         143/Warner Records
31:                                Darkroom/Interscope Records
32:                                           Atlantic Records
33:                                              Parlophone UK
34:                                                   Columbia
35:                                              Sony Music UK
36:                                      Castle Communications
37:                                             Rhino Atlantic
38:                                             Sony/ATV Music
39:                                                   Positiva
40:                                   Sony Music Entertainment
41:                                            ZTT Records Ltd
42:                                                    Geffen*
43:                                                   Columbia
44:                                      Universal Music Group
45:                                           Records/Columbia
46:                                                 Syco Music
47:                                          Capitol Nashville
48:                                              Parlophone UK
49:                                              MCA Nashville
50:                                      Universal Music Group
51:                                           Big Moon Records
52:                                                     rooArt
53:                                                Zoo Digital
54:                                         CM BLUE NOTE (A92)
55:                                                      Rhino
56:                                                       Epic
57:                                          Capitol Nashville
58:                                                    Geffen*
59:                                         14th Floor Records
60:                                      Universal Music Group
61:                                      Universal Music Group
62:                                       Universal Music Ltd.
63:                                                       Epic
64:                                           Republic Records
65:                                                    Reprise
66:                                            Scepter Records
67:                                               RBMG/Def Jam
68:                                     Capitol Records (US1A)
69:                                                 RCA/Legacy
70:                                                    Reprise
71:                                                   Darkroom
72:                                 Arista Records/RCA Records
73:                                                       Epic
74:                                                        U-5
75: Friends Keep Secrets/Def Jam Recordings/Interscope Records
76:                                              See For Miles
77:                                      Universal Music Group
78:                                      Universal Music Group
79:                                Classic Music International
80:                                              XL Recordings
81:                                        Atlantic Records UK
82:                                                Epic/Legacy
83:                                          Universal Records
84:                                              Parlophone UK
85:                                                      Rhino
86:                                             Warner Records
87:                                        Concord Music Group
88:                                             Rhino Atlantic
                                                         label
                                                                                                                                                                                                                                                                                                                              copyrights
                                                                                                                                                                                                                                                                                                                                  <char>
 1:                                                                                                                                                                                                                                                                                     C © 1987 Geffen Records, P ℗ 1987 Geffen Records
 2:                                                                                                                                                                                                                                                                                                                       C 2014, P 2014
 3:                                                                                                                                                                                               C © 1990 The Verve Music Group, a Division of UMG Recordings, Inc., P ℗ 1965 The Verve Music Group, a Division of UMG Recordings, Inc.
 4:                                                                                                                                                C © 2018 The Really Useful Group Ltd., under exclusive licence to Polydor Limited, P This Compilation ℗ 2018 The Really Useful Group Ltd., under exclusive licence to Polydor Limited
 5:                                                                                                                                                                                                       C © 1990 Universal Records, a Division of UMG Recordings, Inc., P ℗ 1990 Universal Records, a Division of UMG Recordings, Inc.
 6:                                                                                                                                                                                                               P (P) 2011 Sensibility Records LLC & The Civil Wars LLC under exclusive license to Sony Music Entertainment UK Limited
 7:                                                                                               C © 2013 WaterTower Music Inc., under exclusive license to Decca, a division of Universal Music Operations Limited, P ℗ 2013 WaterTower Music Inc., under exclusive license to Decca, a division of Universal Music Operations Limited
 8:                                                                                                                                                                                                                                                                                                        P (P) 1992 Arista Records LLC
 9:                                                                                                                                                                                                                                                                                   C © 2018 Capitol Records, P ℗ 2018 Capitol Records
10:                                                                                                                                                                                                                                                                                   C © 2016 Reprise Records, P ℗ 2016 Reprise Records
11:                                                                                                                                                                                                                                                                                                                                 <NA>
12:                                                                                                                                                                                                                                                                         C © 2022 Capitol Records, LLC, P ℗ 2022 Capitol Records, LLC
13:                                                                                                                                                                                                                                                                               C © 2002 Blue Note Records, P ℗ 2002 Blue Note Records
14:                                                                                                                                                                                                                                                                                     C © 2006 Spectrum Music, P ℗ 2006 Spectrum Music
15:                                                                                                                                                                                                                    P (P) 2014 Left Lane Recordings exclusively licensed to Sony Music Entertainment Netherlands B.V. / Ultra Records
16:                                                                                                                                                                                                    C © 1960 Warner Records Inc., P ℗ 1960 Warner Records Inc. Marketed by Rhino Entertainment Company, a Warner Music Group Company.
17:                                                                                                                                                                                                                                                                   C © 2011 Warner Music UK Limited, P ℗ 2011 Warner Music UK Limited
18:                                                                                                                                                                                                                         P (P) 1987 Sony Music Entertainment UK Limited under exclusive license to BMG Rights Management (UK) Limited
19:                                                                                                                                                                                                                                                                                                       P (P)1988 BMG Records (UK) Ltd
20:                                                                                                       C © 2016 Jasmine Van Den Bogaerde under exclusive licence to Atlantic Records UK, a Warner Music Group company, P ℗ 2016 Jasmine Van Den Bogaerde under exclusive licence to Atlantic Records UK, a Warner Music Group company
21:                                                                                                                                                                                                                                                                                             P (P) 2002 Sony Music Entertainment Inc.
22:                                                                                                                                                                                                                                                                                   C © 2016 Capitol Records, P ℗ 2016 Capitol Records
23:                                                                                                                                                                                                                                                                     C © 1991 Virgin Records Limited, P ℗ 1991 Virgin Records Limited
24:                                                                                                                                                                                                                                                     C © 2009 The Island Def Jam Music Group, P ℗ 2009 The Island Def Jam Music Group
25:                                                                                                                                                                                                                                                                                                 P (P) 1990 BMG Arista/Ariola Limited
26:                                                                                                                                                                                                                                                                                   C 2005 Gusto Records Inc, P 2005 Gusto Records Inc
27:                                                                                                                                                                                                                                                                           C © 1996 Warner Records Inc., P ℗ 1996 Warner Records Inc.
28:                                                                                                                                                                                                                                                                             P This compilation (P) 2005 SONY BMG MUSIC (CANADA) INC.
29:                                                                                                                                                                                                                                                                     C (C) 2015 Capitol Records Ltd., P (P) 2015 Capitol Records Ltd.
30:                                                                                                                                                                                                                                                                           C © 2006 Warner Records Inc., P ℗ 2006 Warner Records Inc.
31:                                                                                                                                                                                                                                                           C © 2019 Darkroom/Interscope Records, P ℗ 2019 Darkroom/Interscope Records
32: C © 2015 Atlantic Recording Corporation for the United States and WEA International Inc. for the world outside of the United States. A Warner Music Group Company, P ℗ 2015 Atlantic Recording Corporation for the United States and WEA International Inc. for the world outside of the United States. A Warner Music Group Company
33:                                                                                                                                                                                                         C © 1990 Parlophone Records Ltd, a Warner Music Group Company, P ℗ 1990 Parlophone Records Ltd, a Warner Music Group Company
34:                                                                                                                                                                                                                                                                                    P (P) 2014 Twentieth Century Fox Film Corporation
35:                                                                                                                                                                                                                                                                                       P (P) 1999 Sony Music Entertainment UK Limited
36:                                                                                                                                                                                                                           C © 2003 Sanctuary Records Group Ltd., a BMG Company, P ℗ 2003 Sanctuary Records Group Ltd., a BMG Company
37:                                                                                                                                                   C © 2005 Atlantic Recording Corp. Manufactured & Marketed by Warner Strategic Marketing., P ℗ 2005 Atlantic Recording Corp. Manufactured & Marketed by Warner Strategic Marketing.
38:                                                                                                                                                                                                                                                                                                        C (C) 2016 Sony/ATV Nashville
39:                                                                                                                                                                                                                                             C © 2016 Universal Music Operations Limited, P ℗ 2016 Universal Music Operations Limited
40:                                                                                                                                                                                                                                                                               P (P) 2016 Sony Music Entertainment Australia Pty Ltd.
41:                                                                                                                                                                                                                                                                                                          C (C) 1985 ZTT Records Ltd.
42:                                                                                                                                                                                                                                                                C © 1999 MCA Records Inc., P This Compilation ℗ 1999 MCA Records Inc.
43:                                                                                                                                                                                                                                                                                                 P 1996 Sony Music Entertainment Inc.
44:                                                                                                                                                                                                                                                     C © 2009 The Island Def Jam Music Group, P ℗ 2009 The Island Def Jam Music Group
45:                                                                                                                                                                                                                                                                                             P (P) 2020 Records Label, LLC / Columbia
46:                                                                                                                                                                                                                                              P (P) 2014 Simco Limited under exclusive licence to Sony Music Entertainment UK Limited
47:                                                                                                                             C (C) 1991 Capitol Records, Inc., P Compilation (P) 1991 Capitol Records Nashville. All rights reserved. Unauthorized reproduction is a violation of applicable laws. Manufactured by Nashville Catalog,
48:                                                                                                                                                                                                         C © 1988 Parlophone Records Ltd, a Warner Music Group Company, P ℗ 1988 Parlophone Records Ltd, a Warner Music Group Company
49:                                                                                                                                                                                              C © 2004 MCA Nashville, a Division of UMG Recordings, Inc., P This Compilation ℗ 2015 MCA Nashville, a Division of UMG Recordings, Inc.
50:                                                                                                                                                                                                             C © 1995 Bjork Overseas Ltd./One Little Indian Records Ltd., P ℗ 1995 Bjork Overseas Ltd./One Little Indian Records Ltd.
51:                                                                                                                                                                                                                                                                                     C 1979 Big Moon Records, P 1979 Big Moon Records
52:                                                                                                                                                                                                                                                                                                            P (P) 1995 rooArt Pty Ltd
53:                                                                                                                                                                                                                           C 2013 Zoo Digital, a division of zooland Music GmbH, P 2013 Zoo Digital, a division of zooland Music GmbH
54:                                                                                                                                                                                                                                                                         C © 2022 Capitol Records, LLC, P ℗ 2022 Capitol Records, LLC
55:                                                                                                                                                     C © 2004 Warner Special Products. Manufactured & Marketed by Warner Strategic Marketing, P ℗ 2004 Warner Special Products. Manufactured & Marketed by Warner Strategic Marketing
56:                                                                                                                                                                                                                                                                      P (P) 2014 Epic Records, a division of Sony Music Entertainment
57:                                                                                                                                                                                                                                              C © 1998 Capitol Records Nashville, P This Compilation ℗ 1998 Capitol Records Nashville
58:                                                                                                                                                                                                                                                                             C © 1987 MCA Records Inc., P ℗ 1987 UMG Recordings, Inc.
59:                                                                                                                                                                                                               C © 2004 DRM under exclusive licence to 14th Floor Records, P ℗ 2002 DRM under exclusive licence to 14th Floor Records
60:                                                                                                                                                                                                       C © 1959 Universal Records, a Division of UMG Recordings, Inc., P ℗ 1959 Universal Records, a Division of UMG Recordings, Inc.
61:                                                                                                                                                                                                                                                                                   C © 2018 Capitol Records, P ℗ 2018 Capitol Records
62:                                                                                                                                                                                                                                                                     C (C) 2015 Capitol Records Ltd., P (P) 2015 Capitol Records Ltd.
63:                                                                                                                                                                                                                                                                      P (P) 1986 Epic Records, a division of Sony Music Entertainment
64:                                                                                                                                                                                                         C © 2018 Republic Records, a division of UMG Recordings, Inc., P ℗ 2018 Republic Records, a division of UMG Recordings, Inc.
65:                                                                                                                                                                                                                                                                                   C © 2016 Reprise Records, P ℗ 2016 Reprise Records
66:                                                                                                                                                                                                                                                                               C 2005 Gusto Records, Inc., P 2005 Gusto Records, Inc.
67:                                                                                                                                                                                                                                                     C © 2013 The Island Def Jam Music Group, P ℗ 2013 The Island Def Jam Music Group
68:                                                                                                                                                                                                                                                                                   C © 2018 Capitol Records, P ℗ 2018 Capitol Records
69:                                                                                                                                                                                                                                                                       P (P) 1975 RCA Records, a division of Sony Music Entertainment
70:                                                                                                                                                                                                                                                                                   C © 2016 Reprise Records, P ℗ 2016 Reprise Records
71:                                                                                                                                                                                                                                                           C © 2018 Darkroom/Interscope Records, P ℗ 2018 Darkroom/Interscope Records
72:                                                                                                                                                                                                                                                                       P (P) 2012 RCA Records, a division of Sony Music Entertainment
73:                                                                                                                                                                                                                                                                P (P) 2013, 2014 Epic Records, a division of Sony Music Entertainment
74:                                                                                                                                                                                                                                                                                                               C 2014 U-5, P 2014 U-5
75:                                                                                                                                                                                             C © 2020 Friends Keep Secrets/Def Jam Recordings/Interscope Records, P ℗ 2020 Friends Keep Secrets/Def Jam Recordings/Interscope Records
76:                                                                                                                                                                                                                                                                   C 1994 See For Miles Records Ltd, P 1994 See For Miles Records Ltd
77:                                                                                                                                                                               C © 2015 Capitol Records, a division of Universal Music Operations Limited, P ℗ 2015 Capitol Records, a division of Universal Music Operations Limited
78:                                                                                                                                                                               C © 2015 Capitol Records, a division of Universal Music Operations Limited, P ℗ 2015 Capitol Records, a division of Universal Music Operations Limited
79:                                                                                                                                                                                                                                                               C 2011 Classic Music International, P 2011 Classic Music International
80:                                                                                                                                                                                                                                                                                 C 2008 XL Recordings Ltd., P 2008 XL Recordings Ltd.
81:                                                                                                       C © 2016 Jasmine Van Den Bogaerde under exclusive licence to Atlantic Records UK, a Warner Music Group company, P ℗ 2016 Jasmine Van Den Bogaerde under exclusive licence to Atlantic Records UK, a Warner Music Group company
82:                                                                                                                                                                                                                               P Originally Released 1962, 1963, 1964, 1965, 1967, 1968, (P) 1972, 2004 Sony Music Entertainment Inc.
83:                                                                                                                                                                                                                                                                         C © 1965 UMG Recordings, Inc., P ℗ 1965 UMG Recordings, Inc.
84:                                                                                                                                                                                                         C © 2013 Parlophone Records Ltd, a Warner Music Group Company, P ℗ 2013 Parlophone Records Ltd, a Warner Music Group Company
85:                                                                                                                                                                                                                                                                         C © 2004 Warner Music UK Ltd., P ℗ 2004 Warner Music UK Ltd.
86:                                                                                                                                                                                                                                                                C © 1993 Warner Records Inc., P ℗ 1972, 1973 1993 Warner Records Inc.
87:                                                                                                                                                                                                                                                                   C 1994 Concord Music Group, Inc., P 1994 Concord Music Group, Inc.
88:                                                                                                                                                                                                                 C © 1979 Atlantic Records., P ℗ 1979 Atlantic Records. Marketed by Rhino Entertainment, a Warner Music Group Company
                                                                                                                                                                                                                                                                                                                              copyrights
    main_genre
        <char>
 1:        Pop
 2:        Pop
 3:        Pop
 4:        Pop
 5:        Pop
 6:        Pop
 7:        Pop
 8:        Pop
 9:        Pop
10:        Pop
11:        Pop
12:        Pop
13:        Pop
14:        Pop
15:        Pop
16:        Pop
17:        Pop
18:        Pop
19:        Pop
20:        Pop
21:        Pop
22:        Pop
23:        Pop
24:        Pop
25:        Pop
26:        Pop
27:        Pop
28:        Pop
29:        Pop
30:        Pop
31:        Pop
32:        Pop
33:        Pop
34:        Pop
35:        Pop
36:        Pop
37:        Pop
38:        Pop
39:        Pop
40:        Pop
41:        Pop
42:        Pop
43:        Pop
44:        Pop
45:        Pop
46:        Pop
47:        Pop
48:        Pop
49:        Pop
50:        Pop
51:        Pop
52:        Pop
53:        Pop
54:        Pop
55:        Pop
56:        Pop
57:        Pop
58:        Pop
59:        Pop
60:        Pop
61:        Pop
62:        Pop
63:        Pop
64:        Pop
65:        Pop
66:        Pop
67:        Pop
68:        Pop
69:        Pop
70:        Pop
71:        Pop
72:        Pop
73:        Pop
74:        Pop
75:        Pop
76:        Pop
77:        Pop
78:        Pop
79:        Pop
80:        Pop
81:        Pop
82:        Pop
83:        Pop
84:        Pop
85:        Pop
86:        Pop
87:        Pop
88:        Pop
    main_genre
# Exclude songs with a time signature of 4
spotify_dt[time_signature != 4]
                                              track_name     artist_name_s
                                                  <char>            <char>
  1: Writing's On The Wall - From ""Spectre"" Soundtrack         Sam Smith
  2:                                     Dangerous Woman     Ariana Grande
  3:                               The Wild Colonial Boy          Dr. Hook
  4:                                   You Talk Too Much         Joe Jones
  5:                                       Come & Get It      Selena Gomez
 ---                                                                      
466:                  Somebody To Love - Remastered 2011             Queen
467:                 Love Has No Pride - 2017 Remastered Daryl Braithwaite
468:                                  Georgia On My Mind       Ray Charles
469:                                             imagine     Ariana Grande
470:                                       One More Time        Real McCoy
                                              album_name album_artist_name_s
                                                  <char>              <char>
  1:                               Writing's On The Wall           Sam Smith
  2:                                     Dangerous Woman       Ariana Grande
  3:                                            Timeless            Dr. Hook
  4:                     You Talk Too Much - The Best Of           Joe Jones
  5:                                         Stars Dance        Selena Gomez
 ---                                                                        
466:                  A Day At The Races (2011 Remaster)               Queen
467: Days Go By: The Definitive Greatest Hits Collection   Daryl Braithwaite
468:                                  Georgia On My Mind         Ray Charles
469:                                       thank u, next       Ariana Grande
470:                                       One More Time          Real McCoy
     album_release_date disc_number track_number track_duration_ms explicit
                 <char>       <int>        <int>             <int>   <lgcl>
  1:         2015-09-25           1            1            278987    FALSE
  2:         2016-05-20           1            2            235946    FALSE
  3:         2015-04-17           1           41            266669    FALSE
  4:         2010-07-01           1            1            152706    FALSE
  5:         2013-01-01           1            5            231986    FALSE
 ---                                                                       
466:         1976-12-10           1            6            296480    FALSE
467:         2017-11-24           2           11            203066    FALSE
468:         2012-02-23           1            1            216613    FALSE
469:         2018-02-07           1            1            212266    FALSE
470:         1997-03-25           1            1            238706    FALSE
     popularity         isrc                 added_by            added_at
          <int>       <char>                   <char>              <POSc>
  1:         68 GBUM71505354 spotify:user:bradnumber1 2021-08-08 09:26:31
  2:          0 USUM71601826 spotify:user:bradnumber1 2021-08-08 09:26:31
  3:         19 GBUM71302541 spotify:user:bradnumber1 2021-08-08 09:26:31
  4:         13 USA561018172 spotify:user:bradnumber1 2021-08-08 09:26:31
  5:          0 USHR11334422 spotify:user:bradnumber1 2021-08-08 09:26:31
 ---                                                                     
466:          0 GBUM71029613 spotify:user:bradnumber1 2021-08-08 09:26:31
467:         14 AUYJL1700005 spotify:user:bradnumber1 2021-08-08 09:26:31
468:         45 FR6V81229416 spotify:user:bradnumber1 2021-08-08 09:26:31
469:         37 USUM71822237 spotify:user:bradnumber1 2021-08-08 09:26:31
470:         43 DEC739701185 spotify:user:bradnumber1 2021-08-08 09:26:31
                                                      artist_genres
                                                             <char>
  1:                                                     pop,uk pop
  2:                                                            pop
  3:                             country rock,mellow gold,soft rock
  4:                                                        novelty
  5:                                              pop,post-teen pop
 ---                                                               
466:                                    classic rock,glam rock,rock
467:                                 australian pop,australian rock
468: classic soul,jazz blues,piano blues,soul,soul blues,vocal jazz
469:                                                            pop
470:                   diva house,eurodance,german techno,hip house
     danceability energy   key loudness  mode speechiness acousticness
            <num>  <num> <int>    <num> <int>       <num>        <num>
  1:        0.261  0.302     5   -8.190     0      0.0339     0.769000
  2:        0.677  0.604     7   -5.320     1      0.0385     0.061200
  3:        0.448  0.312     1  -14.926     1      0.0552     0.840000
  4:        0.719  0.639     8   -9.229     1      0.0376     0.797000
  5:        0.349  0.795     7   -4.133     0      0.0758     0.010200
 ---                                                                  
466:        0.461  0.690     8   -6.958     1      0.0611     0.169000
467:        0.382  0.429     5   -7.054     1      0.0269     0.182000
468:        0.282  0.247     7  -11.838     1      0.0305     0.839000
469:        0.727  0.480     8   -4.929     1      0.0434     0.347000
470:        0.671  0.862     5  -11.367     1      0.0351     0.000889
     instrumentalness liveness valence   tempo time_signature album_genres
                <num>    <num>   <num>   <num>          <int>       <lgcl>
  1:         2.57e-06   0.0863  0.0883  81.418              3           NA
  2:         0.00e+00   0.3530  0.2970 134.052              3           NA
  3:         3.80e-06   0.0848  0.4030 158.270              3           NA
  4:         1.43e-05   0.0750  0.7270 128.272              1           NA
  5:         1.38e-04   0.0812  0.5420 148.985              1           NA
 ---                                                                      
466:         1.01e-06   0.1130  0.3530 110.915              3           NA
467:         0.00e+00   0.2140  0.2640  89.017              3           NA
468:         0.00e+00   0.1440  0.2550 112.146              5           NA
469:         0.00e+00   0.1080  0.3630  62.574              3           NA
470:         7.00e-01   0.1670  0.8550 133.117              3           NA
                                   label
                                  <char>
  1:                             Capitol
  2:               Universal Music Group
  3: Universal Music Australia Pty. Ltd.
  4:                  Brownbeats Records
  5:                     Universal Music
 ---                                    
466:               Universal Music Group
467:            Sony Music Entertainment
468:                                 DOM
469:                    Republic Records
470:                           RCA/Hansa
                                                                                                                                                                                   copyrights
                                                                                                                                                                                       <char>
  1:                                   C © 2015 Capitol Records, a division of Universal Music Operations Limited, P ℗ 2015 Capitol Records, a division of Universal Music Operations Limited
  2:                                                             C © 2016 Republic Records, a division of UMG Recordings, Inc., P ℗ 2016 Republic Records, a division of UMG Recordings, Inc.
  3:                                                                                C © 2015 Universal Music Australia Pty Ltd., P This Compilation ℗ 2015 Universal Music Australia Pty Ltd.
  4:                                                                                                                             C (C) 2010 Goldenlane Records, P (P) 2010 Goldenlane Records
  5:                                                                                                                       C © 2013 Hollywood Records, Inc., P ℗ 2013 Hollywood Records, Inc.
 ---                                                                                                                                                                                         
466: C © 2011 Queen Productions Ltd. under exclusive licence to Universal International Music BV, P ℗ 2011 Queen Productions Ltd. under exclusive licence to Universal International Music BV
467:                                                                                                                                    P (P) 2017 Sony Music Entertainment Australia Pty Ltd
468:                                                                                                                                                                             C DOM, P DOM
469:                                                             C © 2019 Republic Records, a division of UMG Recordings, Inc., P ℗ 2019 Republic Records, a division of UMG Recordings, Inc.
470:                                                                                                                                                                     P (P) 1997 Hansa/BMG
           main_genre
               <char>
  1:              Pop
  2:              Pop
  3:             Rock
  4:            Other
  5:              Pop
 ---                 
466:             Rock
467:              Pop
468:         R&B/Soul
469:              Pop
470: Dance/Electronic

AS a reminder

Comparison Operators

  • == means “exactly equal to”
  • != means “not equal to”
  • > means “greater than”
  • < means “less than”
  • >= means “greater than or equal to”
  • <= means “less than or equal to”

Logical Operators

  • & means “AND” (both conditions must be true)
  • | means “OR” (at least one condition must be true)
  • ! means “NOT” (reverses the condition)

2.) Column Operations (j)

The j argument lets you select columns and perform computations:

# Select specific columns
spotify_dt[, .(track_name, artist_name_s, popularity)]
                                                      track_name
                                                          <char>
   1:                    Justified & Ancient - Stand by the Jams
   2:                            I Know You Want Me (Calle Ocho)
   3:                         From the Bottom of My Broken Heart
   4:                           Apeman - 2014 Remastered Version
   5:                         You Can't Always Get What You Want
  ---                                                           
9995:                               Kernkraft 400 (A Better Day)
9996:                               Never Say Never - Radio Edit
9997: Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
9998:                                                    Lay Low
9999:                                                Padam Padam
                     artist_name_s popularity
                            <char>      <int>
   1:                      The KLF          0
   2:                      Pitbull         64
   3:               Britney Spears         56
   4:                    The Kinks         42
   5:           The Rolling Stones          0
  ---                                        
9995:                   Topic, A7S         79
9996:                    Vandalism         17
9997: Spiller, Sophie Ellis-Bextor         62
9998:                       Tiësto         87
9999:                Kylie Minogue         69
# Compute summary statistics
spotify_dt[, .(avg_popularity = mean(popularity),
              max_energy = max(energy))]
   avg_popularity max_energy
            <num>      <num>
1:       37.62466         NA
# Multiple computations
spotify_dt[, .(
  track_count = .N,
  avg_duration = mean(track_duration_ms)/1000,
  avg_popularity = mean(popularity)
)]
   track_count avg_duration avg_popularity
         <int>        <num>          <num>
1:        9999      224.815       37.62466
# Select specific columns
spotify_dt[, .(artist_name_s, track_name)]
                     artist_name_s
                            <char>
   1:                      The KLF
   2:                      Pitbull
   3:               Britney Spears
   4:                    The Kinks
   5:           The Rolling Stones
  ---                             
9995:                   Topic, A7S
9996:                    Vandalism
9997: Spiller, Sophie Ellis-Bextor
9998:                       Tiësto
9999:                Kylie Minogue
                                                      track_name
                                                          <char>
   1:                    Justified & Ancient - Stand by the Jams
   2:                            I Know You Want Me (Calle Ocho)
   3:                         From the Bottom of My Broken Heart
   4:                           Apeman - 2014 Remastered Version
   5:                         You Can't Always Get What You Want
  ---                                                           
9995:                               Kernkraft 400 (A Better Day)
9996:                               Never Say Never - Radio Edit
9997: Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
9998:                                                    Lay Low
9999:                                                Padam Padam
# Create new columns in output
spotify_dt[, .(
  song = track_name,
  artist = artist_name_s,
  popularity_score = popularity/100
)]
                                                            song
                                                          <char>
   1:                    Justified & Ancient - Stand by the Jams
   2:                            I Know You Want Me (Calle Ocho)
   3:                         From the Bottom of My Broken Heart
   4:                           Apeman - 2014 Remastered Version
   5:                         You Can't Always Get What You Want
  ---                                                           
9995:                               Kernkraft 400 (A Better Day)
9996:                               Never Say Never - Radio Edit
9997: Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
9998:                                                    Lay Low
9999:                                                Padam Padam
                            artist popularity_score
                            <char>            <num>
   1:                      The KLF             0.00
   2:                      Pitbull             0.64
   3:               Britney Spears             0.56
   4:                    The Kinks             0.42
   5:           The Rolling Stones             0.00
  ---                                              
9995:                   Topic, A7S             0.79
9996:                    Vandalism             0.17
9997: Spiller, Sophie Ellis-Bextor             0.62
9998:                       Tiësto             0.87
9999:                Kylie Minogue             0.69
# Calculate summary statistics
spotify_dt[, .(
  avg_popularity = mean(popularity),
  total_tracks = .N,
  avg_duration = mean(track_duration_ms)/1000  # in seconds
)]
   avg_popularity total_tracks avg_duration
            <num>        <int>        <num>
1:       37.62466         9999      224.815

✅Now you try:

Selecting and computing (i)

# Select specific columns
spotify_dt[, .(album_name, album_release_date)]
                                                                  album_name
                                                                      <char>
   1:                                                       Songs Collection
   2:                                         Pitbull Starring In Rebelution
   3:                         ...Baby One More Time (Digital Deluxe Version)
   4: Lola vs. Powerman and the Moneygoround, Pt. One + Percy (Super Deluxe)
   5:                                                           Let It Bleed
  ---                                                                       
9995:                                           Kernkraft 400 (A Better Day)
9996:                                                        Never Say Never
9997:             Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
9998:                                                                Lay Low
9999:                                                            Padam Padam
      album_release_date
                  <char>
   1:         1992-08-03
   2:         2009-10-23
   3:         1999-01-12
   4:         2014-10-20
   5:         1969-12-05
  ---                   
9995:         2022-06-17
9996:         2005-10-24
9997:         2000-08-14
9998:         2023-01-06
9999:         2023-05-19
# Calculate the shortest and longest songs in minutes
spotify_dt[, .(
  min_duration = min(track_duration_ms)/60000,
  max_duration = max(track_duration_ms)/60000
)]
   min_duration max_duration
          <num>        <num>
1:            0     26.01888
  1. Grouping Operations (by)
# Group by genre
spotify_dt[, .(
  track_count = .N,
  avg_popularity = mean(popularity),
  avg_danceability = mean(danceability)
), by = main_genre]
                main_genre track_count avg_popularity avg_danceability
                    <char>       <int>          <num>            <num>
 1:       Dance/Electronic         254       32.76378        0.6779331
 2:                    Pop        5694       40.27116        0.6243319
 3:                   Rock        2413       37.57563        0.5480435
 4:                Hip Hop         214       32.50935        0.7607477
 5:                  Other         946       26.09831               NA
 6:               R&B/Soul         302       34.93709        0.6557980
 7:             Jazz/Blues          54       22.24074        0.5241852
 8:           Folk/Country          91       34.65934        0.5683407
 9:       Reggae/Caribbean          27       48.22222        0.7564815
10: Classical/Instrumental           4       14.75000        0.5580000
# Multiple grouping variables
spotify_dt[, .(
  track_count = .N,
  avg_popularity = mean(popularity)
), by = .(main_genre, explicit)]
                main_genre explicit track_count avg_popularity
                    <char>   <lgcl>       <int>          <num>
 1:       Dance/Electronic    FALSE         252       32.81746
 2:                    Pop    FALSE        5345       39.74275
 3:                   Rock    FALSE        2363       37.50994
 4:                Hip Hop    FALSE         132       31.15152
 5:                  Other    FALSE         924       25.98377
 6:               R&B/Soul    FALSE         301       35.05316
 7:                    Pop     TRUE         349       48.36390
 8:             Jazz/Blues    FALSE          54       22.24074
 9:                Hip Hop     TRUE          82       34.69512
10:           Folk/Country    FALSE          89       33.40449
11:       Reggae/Caribbean    FALSE          27       48.22222
12:                   Rock     TRUE          50       40.68000
13:                  Other     TRUE          22       30.90909
14: Classical/Instrumental     TRUE           1        0.00000
15:       Dance/Electronic     TRUE           2       26.00000
16: Classical/Instrumental    FALSE           3       19.66667
17:           Folk/Country     TRUE           2       90.50000
18:               R&B/Soul     TRUE           1        0.00000
# Group by genre for popularity analysis
genre_stats <- spotify_dt[, .(
  avg_popularity = mean(popularity, na.rm = TRUE),
  track_count = .N,
  avg_duration = mean(track_duration_ms)/1000
), by = main_genre][]

✅Now you try:

Grouping (i)

# Group by explicity
spotify_dt[, .(
  track_count = .N,
  avg_popularity = mean(popularity, na.rm = TRUE),
  avg_loudness = mean(loudness, na.rm = TRUE)
), by = explicit]
   explicit track_count avg_popularity avg_loudness
     <lgcl>       <int>          <num>        <num>
1:    FALSE        9490       37.25374    -7.348079
2:     TRUE         509       44.54028    -5.799193

Think of it like a sentence:

i = “Which rows do you want?”

j = “What do you want to do with them?”

by = “How should they be grouped?”

5. Advanced Features

  1. Adding/Updating Columns (:=)

We use the empty brackets at the end to print but you could have also

# Add duration in seconds
spotify_dt[, duration_sec := track_duration_ms/1000][]
Index: <main_genre>
                                                      track_name
                                                          <char>
   1:                    Justified & Ancient - Stand by the Jams
   2:                            I Know You Want Me (Calle Ocho)
   3:                         From the Bottom of My Broken Heart
   4:                           Apeman - 2014 Remastered Version
   5:                         You Can't Always Get What You Want
  ---                                                           
9995:                               Kernkraft 400 (A Better Day)
9996:                               Never Say Never - Radio Edit
9997: Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
9998:                                                    Lay Low
9999:                                                Padam Padam
                     artist_name_s
                            <char>
   1:                      The KLF
   2:                      Pitbull
   3:               Britney Spears
   4:                    The Kinks
   5:           The Rolling Stones
  ---                             
9995:                   Topic, A7S
9996:                    Vandalism
9997: Spiller, Sophie Ellis-Bextor
9998:                       Tiësto
9999:                Kylie Minogue
                                                                  album_name
                                                                      <char>
   1:                                                       Songs Collection
   2:                                         Pitbull Starring In Rebelution
   3:                         ...Baby One More Time (Digital Deluxe Version)
   4: Lola vs. Powerman and the Moneygoround, Pt. One + Percy (Super Deluxe)
   5:                                                           Let It Bleed
  ---                                                                       
9995:                                           Kernkraft 400 (A Better Day)
9996:                                                        Never Say Never
9997:             Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
9998:                                                                Lay Low
9999:                                                            Padam Padam
      album_artist_name_s album_release_date disc_number track_number
                   <char>             <char>       <int>        <int>
   1:             The KLF         1992-08-03           1            3
   2:             Pitbull         2009-10-23           1            3
   3:      Britney Spears         1999-01-12           1            6
   4:           The Kinks         2014-10-20           1           11
   5:  The Rolling Stones         1969-12-05           1            9
  ---                                                                
9995:          Topic, A7S         2022-06-17           1            1
9996:           Vandalism         2005-10-24           1            1
9997:             Spiller         2000-08-14           1            1
9998:              Tiësto         2023-01-06           1            1
9999:       Kylie Minogue         2023-05-19           1            1
      track_duration_ms explicit popularity         isrc
                  <int>   <lgcl>      <int>       <char>
   1:            216270    FALSE          0 QMARG1760056
   2:            237120    FALSE         64 USJAY0900144
   3:            312533    FALSE         56 USJI19910455
   4:            233400    FALSE         42 GB5KW1499822
   5:            448720    FALSE          0 USA176910100
  ---                                                   
9995:            165800    FALSE         79 DECE72201091
9996:            176640    FALSE         17 AUVC00503711
9997:            227619    FALSE         62 GBCPZ0019728
9998:            153442    FALSE         87 NLZ542202348
9999:            166266    FALSE         69 GB5KW2301017
                      added_by            added_at
                        <char>              <POSc>
   1: spotify:user:bradnumber1 2020-03-05 09:20:39
   2: spotify:user:bradnumber1 2021-08-08 09:26:31
   3: spotify:user:bradnumber1 2021-08-08 09:26:31
   4: spotify:user:bradnumber1 2021-08-08 09:26:31
   5: spotify:user:bradnumber1 2021-08-08 09:26:31
  ---                                             
9995: spotify:user:bradnumber1 2023-07-11 10:57:25
9996: spotify:user:bradnumber1 2023-07-16 09:38:19
9997: spotify:user:bradnumber1 2023-07-16 09:39:17
9998: spotify:user:bradnumber1 2023-07-18 22:06:36
9999: spotify:user:bradnumber1 2023-07-25 11:57:02
                                                                                                                artist_genres
                                                                                                                       <char>
   1:                                                                             acid house,ambient house,big beat,hip house
   2:                                                                                             dance pop,miami hip hop,pop
   3:                                                                                                           dance pop,pop
   4: album rock,art rock,british invasion,classic rock,folk rock,glam rock,protopunk,psychedelic rock,rock,singer-songwriter
   5:                                                                           album rock,british invasion,classic rock,rock
  ---                                                                                                                        
9995:                                                    german dance,pop dance,pop edm,uk dance,pop dance,scandipop,uk dance
9996:                                                                                       australian dance,melbourne bounce
9997:                                                                  disco house,vocal house,dance pop,europop,new wave pop
9998:                                                        big room,brostep,dutch edm,edm,house,pop dance,slap house,trance
9999:                                                        australian dance,australian pop,dance pop,eurodance,new wave pop
      danceability energy   key loudness  mode speechiness acousticness
             <num>  <num> <int>    <num> <int>       <num>        <num>
   1:        0.617  0.872     8  -12.305     1      0.0480     0.015800
   2:        0.825  0.743     2   -5.995     1      0.1490     0.014200
   3:        0.677  0.665     7   -5.171     1      0.0305     0.560000
   4:        0.683  0.728     9   -8.920     1      0.2590     0.568000
   5:        0.319  0.627     0   -9.611     1      0.0687     0.675000
  ---                                                                  
9995:        0.623  0.727    11   -5.570     0      0.0562     0.184000
9996:        0.720  0.841     9   -6.373     1      0.0340     0.000354
9997:        0.719  0.806     9   -6.802     0      0.0389     0.000132
9998:        0.534  0.855     1   -4.923     0      0.1830     0.060700
9999:        0.744  0.620     5   -7.930     1      0.2460     0.214000
      instrumentalness liveness valence   tempo time_signature album_genres
                 <num>    <num>   <num>   <num>          <int>       <lgcl>
   1:         1.12e-01   0.4080   0.504 111.458              4           NA
   2:         2.12e-05   0.2370   0.800 127.045              4           NA
   3:         1.01e-06   0.3380   0.706  74.981              4           NA
   4:         5.08e-05   0.0384   0.833  75.311              4           NA
   5:         7.29e-05   0.2890   0.497  85.818              4           NA
  ---                                                                      
9995:         2.02e-05   0.3090   0.400 125.975              4           NA
9996:         1.12e-02   0.3380   0.767 130.978              4           NA
9997:         8.89e-02   0.3610   0.626 123.037              4           NA
9998:         2.63e-04   0.3460   0.420 122.060              4           NA
9999:         1.16e-03   0.1030   0.711 128.103              4           NA
                                    label
                                   <char>
   1:                 Jams Communications
   2: Mr.305/Polo Grounds Music/J Records
   3:                                Jive
   4:                   Sanctuary Records
   5:               Universal Music Group
  ---                                    
9995:                              Virgin
9996:                             Vicious
9997:                    Defected Records
9998:                     Musical Freedom
9999:                     Liberator Music
                                                                                                                                                                                    copyrights
                                                                                                                                                                                        <char>
   1:                                                                                                                                     C 1992 Copyright Control, P 1992 Jams Communications
   2:                                                                                                                      P (P) 2009 RCA/JIVE Label Group, a unit of Sony Music Entertainment
   3:                                                                                                                                                           P (P) 1999 Zomba Recording LLC
   4:                                                                               C © 2014 Sanctuary Records Group Ltd., a BMG Company, P ℗ 2014 Sanctuary Records Group Ltd., a BMG Company
   5:                                                                                                                 C © 2002 ABKCO Music & Records Inc., P ℗ 2002 ABKCO Music & Records Inc.
  ---                                                                                                                                                                                         
9995:                                                         C © 2022 Topic, under exclusive license to Universal Music GmbH, P ℗ 2022 Topic, under exclusive license to Universal Music GmbH
9996:                                                                       C 2005 Vicious, a division of Vicious Recordings Pty Ltd, P 2005 Vicious, a division of Vicious Recordings Pty Ltd
9997:                                                                                                                     C © 2021 Defected Records Limited, P ℗ 2021 Defected Records Limited
9998:                                                                                                                 C © 2023 Musical Freedom Label Ltd., P ℗ 2023 Musical Freedom Label Ltd.
9999: C 2023 Kylie Minogue/Darenote under exclusive license to BMG Rights Management (UK) Limited, P 2023 Kylie Minogue/Darenote under exclusive license to BMG Rights Management (UK) Limited
            main_genre duration_sec
                <char>        <num>
   1: Dance/Electronic      216.270
   2:              Pop      237.120
   3:              Pop      312.533
   4:             Rock      233.400
   5:             Rock      448.720
  ---                              
9995:              Pop      165.800
9996: Dance/Electronic      176.640
9997:              Pop      227.619
9998:              Pop      153.442
9999:              Pop      166.266
# Multiple column updates
spotify_dt[, ':='(
  popularity_scaled = popularity/100,
  is_popular = popularity > 75
)]

spotify_dt
Index: <main_genre>
                                                      track_name
                                                          <char>
   1:                    Justified & Ancient - Stand by the Jams
   2:                            I Know You Want Me (Calle Ocho)
   3:                         From the Bottom of My Broken Heart
   4:                           Apeman - 2014 Remastered Version
   5:                         You Can't Always Get What You Want
  ---                                                           
9995:                               Kernkraft 400 (A Better Day)
9996:                               Never Say Never - Radio Edit
9997: Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
9998:                                                    Lay Low
9999:                                                Padam Padam
                     artist_name_s
                            <char>
   1:                      The KLF
   2:                      Pitbull
   3:               Britney Spears
   4:                    The Kinks
   5:           The Rolling Stones
  ---                             
9995:                   Topic, A7S
9996:                    Vandalism
9997: Spiller, Sophie Ellis-Bextor
9998:                       Tiësto
9999:                Kylie Minogue
                                                                  album_name
                                                                      <char>
   1:                                                       Songs Collection
   2:                                         Pitbull Starring In Rebelution
   3:                         ...Baby One More Time (Digital Deluxe Version)
   4: Lola vs. Powerman and the Moneygoround, Pt. One + Percy (Super Deluxe)
   5:                                                           Let It Bleed
  ---                                                                       
9995:                                           Kernkraft 400 (A Better Day)
9996:                                                        Never Say Never
9997:             Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
9998:                                                                Lay Low
9999:                                                            Padam Padam
      album_artist_name_s album_release_date disc_number track_number
                   <char>             <char>       <int>        <int>
   1:             The KLF         1992-08-03           1            3
   2:             Pitbull         2009-10-23           1            3
   3:      Britney Spears         1999-01-12           1            6
   4:           The Kinks         2014-10-20           1           11
   5:  The Rolling Stones         1969-12-05           1            9
  ---                                                                
9995:          Topic, A7S         2022-06-17           1            1
9996:           Vandalism         2005-10-24           1            1
9997:             Spiller         2000-08-14           1            1
9998:              Tiësto         2023-01-06           1            1
9999:       Kylie Minogue         2023-05-19           1            1
      track_duration_ms explicit popularity         isrc
                  <int>   <lgcl>      <int>       <char>
   1:            216270    FALSE          0 QMARG1760056
   2:            237120    FALSE         64 USJAY0900144
   3:            312533    FALSE         56 USJI19910455
   4:            233400    FALSE         42 GB5KW1499822
   5:            448720    FALSE          0 USA176910100
  ---                                                   
9995:            165800    FALSE         79 DECE72201091
9996:            176640    FALSE         17 AUVC00503711
9997:            227619    FALSE         62 GBCPZ0019728
9998:            153442    FALSE         87 NLZ542202348
9999:            166266    FALSE         69 GB5KW2301017
                      added_by            added_at
                        <char>              <POSc>
   1: spotify:user:bradnumber1 2020-03-05 09:20:39
   2: spotify:user:bradnumber1 2021-08-08 09:26:31
   3: spotify:user:bradnumber1 2021-08-08 09:26:31
   4: spotify:user:bradnumber1 2021-08-08 09:26:31
   5: spotify:user:bradnumber1 2021-08-08 09:26:31
  ---                                             
9995: spotify:user:bradnumber1 2023-07-11 10:57:25
9996: spotify:user:bradnumber1 2023-07-16 09:38:19
9997: spotify:user:bradnumber1 2023-07-16 09:39:17
9998: spotify:user:bradnumber1 2023-07-18 22:06:36
9999: spotify:user:bradnumber1 2023-07-25 11:57:02
                                                                                                                artist_genres
                                                                                                                       <char>
   1:                                                                             acid house,ambient house,big beat,hip house
   2:                                                                                             dance pop,miami hip hop,pop
   3:                                                                                                           dance pop,pop
   4: album rock,art rock,british invasion,classic rock,folk rock,glam rock,protopunk,psychedelic rock,rock,singer-songwriter
   5:                                                                           album rock,british invasion,classic rock,rock
  ---                                                                                                                        
9995:                                                    german dance,pop dance,pop edm,uk dance,pop dance,scandipop,uk dance
9996:                                                                                       australian dance,melbourne bounce
9997:                                                                  disco house,vocal house,dance pop,europop,new wave pop
9998:                                                        big room,brostep,dutch edm,edm,house,pop dance,slap house,trance
9999:                                                        australian dance,australian pop,dance pop,eurodance,new wave pop
      danceability energy   key loudness  mode speechiness acousticness
             <num>  <num> <int>    <num> <int>       <num>        <num>
   1:        0.617  0.872     8  -12.305     1      0.0480     0.015800
   2:        0.825  0.743     2   -5.995     1      0.1490     0.014200
   3:        0.677  0.665     7   -5.171     1      0.0305     0.560000
   4:        0.683  0.728     9   -8.920     1      0.2590     0.568000
   5:        0.319  0.627     0   -9.611     1      0.0687     0.675000
  ---                                                                  
9995:        0.623  0.727    11   -5.570     0      0.0562     0.184000
9996:        0.720  0.841     9   -6.373     1      0.0340     0.000354
9997:        0.719  0.806     9   -6.802     0      0.0389     0.000132
9998:        0.534  0.855     1   -4.923     0      0.1830     0.060700
9999:        0.744  0.620     5   -7.930     1      0.2460     0.214000
      instrumentalness liveness valence   tempo time_signature album_genres
                 <num>    <num>   <num>   <num>          <int>       <lgcl>
   1:         1.12e-01   0.4080   0.504 111.458              4           NA
   2:         2.12e-05   0.2370   0.800 127.045              4           NA
   3:         1.01e-06   0.3380   0.706  74.981              4           NA
   4:         5.08e-05   0.0384   0.833  75.311              4           NA
   5:         7.29e-05   0.2890   0.497  85.818              4           NA
  ---                                                                      
9995:         2.02e-05   0.3090   0.400 125.975              4           NA
9996:         1.12e-02   0.3380   0.767 130.978              4           NA
9997:         8.89e-02   0.3610   0.626 123.037              4           NA
9998:         2.63e-04   0.3460   0.420 122.060              4           NA
9999:         1.16e-03   0.1030   0.711 128.103              4           NA
                                    label
                                   <char>
   1:                 Jams Communications
   2: Mr.305/Polo Grounds Music/J Records
   3:                                Jive
   4:                   Sanctuary Records
   5:               Universal Music Group
  ---                                    
9995:                              Virgin
9996:                             Vicious
9997:                    Defected Records
9998:                     Musical Freedom
9999:                     Liberator Music
                                                                                                                                                                                    copyrights
                                                                                                                                                                                        <char>
   1:                                                                                                                                     C 1992 Copyright Control, P 1992 Jams Communications
   2:                                                                                                                      P (P) 2009 RCA/JIVE Label Group, a unit of Sony Music Entertainment
   3:                                                                                                                                                           P (P) 1999 Zomba Recording LLC
   4:                                                                               C © 2014 Sanctuary Records Group Ltd., a BMG Company, P ℗ 2014 Sanctuary Records Group Ltd., a BMG Company
   5:                                                                                                                 C © 2002 ABKCO Music & Records Inc., P ℗ 2002 ABKCO Music & Records Inc.
  ---                                                                                                                                                                                         
9995:                                                         C © 2022 Topic, under exclusive license to Universal Music GmbH, P ℗ 2022 Topic, under exclusive license to Universal Music GmbH
9996:                                                                       C 2005 Vicious, a division of Vicious Recordings Pty Ltd, P 2005 Vicious, a division of Vicious Recordings Pty Ltd
9997:                                                                                                                     C © 2021 Defected Records Limited, P ℗ 2021 Defected Records Limited
9998:                                                                                                                 C © 2023 Musical Freedom Label Ltd., P ℗ 2023 Musical Freedom Label Ltd.
9999: C 2023 Kylie Minogue/Darenote under exclusive license to BMG Rights Management (UK) Limited, P 2023 Kylie Minogue/Darenote under exclusive license to BMG Rights Management (UK) Limited
            main_genre duration_sec popularity_scaled is_popular
                <char>        <num>             <num>     <lgcl>
   1: Dance/Electronic      216.270              0.00      FALSE
   2:              Pop      237.120              0.64      FALSE
   3:              Pop      312.533              0.56      FALSE
   4:             Rock      233.400              0.42      FALSE
   5:             Rock      448.720              0.00      FALSE
  ---                                                           
9995:              Pop      165.800              0.79       TRUE
9996: Dance/Electronic      176.640              0.17      FALSE
9997:              Pop      227.619              0.62      FALSE
9998:              Pop      153.442              0.87       TRUE
9999:              Pop      166.266              0.69      FALSE

✅Now you try:

# Create new columns
spotify_dt[, `:=`(
  is_popular = popularity > 75,
  loudness_energy_ratio = loudness / energy
)]

# Verify new columns
names(spotify_dt) 
 [1] "track_name"            "artist_name_s"         "album_name"           
 [4] "album_artist_name_s"   "album_release_date"    "disc_number"          
 [7] "track_number"          "track_duration_ms"     "explicit"             
[10] "popularity"            "isrc"                  "added_by"             
[13] "added_at"              "artist_genres"         "danceability"         
[16] "energy"                "key"                   "loudness"             
[19] "mode"                  "speechiness"           "acousticness"         
[22] "instrumentalness"      "liveness"              "valence"              
[25] "tempo"                 "time_signature"        "album_genres"         
[28] "label"                 "copyrights"            "main_genre"           
[31] "duration_sec"          "popularity_scaled"     "is_popular"           
[34] "loudness_energy_ratio"
#from data.table
spotify_dt[, names(.SD)]
 [1] "track_name"            "artist_name_s"         "album_name"           
 [4] "album_artist_name_s"   "album_release_date"    "disc_number"          
 [7] "track_number"          "track_duration_ms"     "explicit"             
[10] "popularity"            "isrc"                  "added_by"             
[13] "added_at"              "artist_genres"         "danceability"         
[16] "energy"                "key"                   "loudness"             
[19] "mode"                  "speechiness"           "acousticness"         
[22] "instrumentalness"      "liveness"              "valence"              
[25] "tempo"                 "time_signature"        "album_genres"         
[28] "label"                 "copyrights"            "main_genre"           
[31] "duration_sec"          "popularity_scaled"     "is_popular"           
[34] "loudness_energy_ratio"

Working with Dates

Here’s how to handle dates in data.table:

# Load lubridate
library(lubridate)

# Convert and extract date components
spotify_dt <- spotify_dt[, `:=`(
  release_date = as.Date(album_release_date),
  release_year = year(as.Date(album_release_date)),
  release_month = month(as.Date(album_release_date)),
  release_day = day(as.Date(album_release_date))
)]

# View the new date columns
spotify_dt[, .(release_date, release_year, release_month, release_day)][1:5]
   release_date release_year release_month release_day
         <Date>        <num>         <num>       <int>
1:   1992-08-03         1992             8           3
2:   2009-10-23         2009            10          23
3:   1999-01-12         1999             1          12
4:   2014-10-20         2014            10          20
5:   1969-12-05         1969            12           5
class(spotify_dt$album_release_date)
[1] "character"

Ordering Results

Data.table provides efficient ways to sort:

# Sort genres by popularity (descending)
genre_stats[order(-avg_popularity)]
                main_genre avg_popularity track_count avg_duration
                    <char>          <num>       <int>        <num>
 1:       Reggae/Caribbean       48.22222          27     210.8963
 2:                    Pop       40.27116        5694     223.3444
 3:                   Rock       37.57563        2413     233.6300
 4:               R&B/Soul       34.93709         302     227.6889
 5:           Folk/Country       34.65934          91     205.5994
 6:       Dance/Electronic       32.76378         254     246.2988
 7:                Hip Hop       32.50935         214     232.4100
 8:                  Other       26.09831         946     208.5390
 9:             Jazz/Blues       22.24074          54     168.0612
10: Classical/Instrumental       14.75000           4     159.5265
# Get top 5 most popular genres
genre_stats[order(-avg_popularity)][1:5]
         main_genre avg_popularity track_count avg_duration
             <char>          <num>       <int>        <num>
1: Reggae/Caribbean       48.22222          27     210.8963
2:              Pop       40.27116        5694     223.3444
3:             Rock       37.57563        2413     233.6300
4:         R&B/Soul       34.93709         302     227.6889
5:     Folk/Country       34.65934          91     205.5994
year_genre_stats <- spotify_dt[, .(
    avg_popularity = mean(popularity),
    track_count = .N,
    avg_energy = mean(energy)
), by = .(release_year)]

# Sort by multiple columns
year_genre_stats[order(release_year, -avg_popularity)]
    release_year avg_popularity track_count avg_energy
           <num>          <num>       <int>      <num>
 1:         1956       68.00000           1  0.6600000
 2:         1958       55.33333           6  0.5676667
 3:         1959       35.00000           2  0.2385000
 4:         1960       61.00000           2  0.8260000
 5:         1961       24.16667           6  0.6656667
 6:         1962       33.57895          19  0.5368947
 7:         1963       32.13333          45  0.5427844
 8:         1964       40.00000          46  0.6658696
 9:         1965       52.51613          31  0.5777097
10:         1966       33.30233          43  0.6424419
11:         1967       44.56250          48  0.5366667
12:         1968       43.87805          41  0.5942927
13:         1969       48.48889          45  0.5497111
14:         1970       50.62500          56  0.5608393
15:         1971       42.90909          44  0.6505000
16:         1972       42.32500          40  0.5486250
17:         1973       49.07273          55  0.5865455
18:         1974       38.13333          30  0.6115667
19:         1975       43.42500          40  0.6191250
20:         1976       50.14634          41  0.6497317
21:         1977       50.55172          58  0.6022759
22:         1978       48.56604          53  0.6504528
23:         1979       44.45283          53  0.6116604
24:         1980       51.33333          45  0.6395556
25:         1981       51.20000          45  0.6677111
26:         1982       47.80851          47  0.6705745
27:         1983       42.55357          56  0.7012679
28:         1984       48.64815          54  0.6755185
29:         1985       40.46154          65  0.7196308
30:         1986       50.05556          72  0.6955417
31:         1987       36.12844         109  0.6350550
32:         1988       40.35294          85  0.6454235
33:         1989       44.08974          78  0.6550231
34:         1990       42.80247          81  0.6516914
35:         1991       38.70787          89  0.6743933
36:         1992       37.28409          88  0.6474659
37:         1993       38.81609          87  0.6679770
38:         1994       39.17073          82  0.6669024
39:         1995       37.00781         128  0.6582813
40:         1996       37.84211         114  0.6303070
41:         1997       39.68217         129  0.7040884
42:         1998       36.08088         136  0.7423088
43:         1999       43.38400         125  0.7390288
44:         2000       36.28859         149  0.7102148
45:         2001       37.68280         186  0.7078441
46:         2002       37.61765         170  0.6864525
47:         2003       36.37500         176  0.7010170
48:         2004       38.66857         175  0.7082629
49:         2005       30.91250         240  0.7182292
50:         2006       33.20321         187  0.6895882
51:         2007       32.03167         221  0.7046335
52:         2008       32.25574         305  0.7465705
53:         2009       31.95455         374  0.7561578
54:         2010       32.20896         335  0.7757433
55:         2011       33.42559         383  0.7296240
56:         2012       35.45299         351  0.7361425
57:         2013       31.26780         295  0.7019861
58:         2014       32.59850         401  0.6773738
59:         2015       32.12250         400  0.6740375
60:         2016       33.14550         378  0.6490534
61:         2017       36.43391         348  0.6564569
62:         2018       43.81609         261  0.6452682
63:         2019       48.44550         211  0.6600806
64:         2020       49.54688         256  0.6631406
65:         2021       41.00966         207  0.6741739
66:         2022       68.91667          60  0.7245000
67:         2023       76.78788          33  0.6893333
68:           NA       36.23457        1377         NA
    release_year avg_popularity track_count avg_energy

🔍 Practice Exercise:

Using the Spotify dataset, create an analysis that:

  1. Filters for songs after 2010

  2. Calculates average audio features by genre

  3. Identifies the top 3 genres by popularity

# solution here
spotify_dt[year(as.Date(album_release_date)) >= 2010,
          .(avg_popularity = mean(popularity),
            avg_danceability = mean(danceability),
            avg_energy = mean(energy),
            track_count = .N),
          by = main_genre
          ][order(-avg_popularity)
          ][1:3]
         main_genre avg_popularity avg_danceability avg_energy track_count
             <char>          <num>            <num>      <num>       <int>
1: Reggae/Caribbean       43.57143        0.7291429  0.7142857           7
2:              Pop       42.13373        0.6329859  0.6930078        2834
3:          Hip Hop       37.21154        0.7300096  0.7036635         104

Ordering Results

Data.table provides efficient ways to sort:

# Sort genres by popularity (descending)
genre_stats[order(-avg_popularity)]
                main_genre avg_popularity track_count avg_duration
                    <char>          <num>       <int>        <num>
 1:       Reggae/Caribbean       48.22222          27     210.8963
 2:                    Pop       40.27116        5694     223.3444
 3:                   Rock       37.57563        2413     233.6300
 4:               R&B/Soul       34.93709         302     227.6889
 5:           Folk/Country       34.65934          91     205.5994
 6:       Dance/Electronic       32.76378         254     246.2988
 7:                Hip Hop       32.50935         214     232.4100
 8:                  Other       26.09831         946     208.5390
 9:             Jazz/Blues       22.24074          54     168.0612
10: Classical/Instrumental       14.75000           4     159.5265
# Sort by multiple columns
year_genre_stats[order(release_year, -avg_popularity)]
    release_year avg_popularity track_count avg_energy
           <num>          <num>       <int>      <num>
 1:         1956       68.00000           1  0.6600000
 2:         1958       55.33333           6  0.5676667
 3:         1959       35.00000           2  0.2385000
 4:         1960       61.00000           2  0.8260000
 5:         1961       24.16667           6  0.6656667
 6:         1962       33.57895          19  0.5368947
 7:         1963       32.13333          45  0.5427844
 8:         1964       40.00000          46  0.6658696
 9:         1965       52.51613          31  0.5777097
10:         1966       33.30233          43  0.6424419
11:         1967       44.56250          48  0.5366667
12:         1968       43.87805          41  0.5942927
13:         1969       48.48889          45  0.5497111
14:         1970       50.62500          56  0.5608393
15:         1971       42.90909          44  0.6505000
16:         1972       42.32500          40  0.5486250
17:         1973       49.07273          55  0.5865455
18:         1974       38.13333          30  0.6115667
19:         1975       43.42500          40  0.6191250
20:         1976       50.14634          41  0.6497317
21:         1977       50.55172          58  0.6022759
22:         1978       48.56604          53  0.6504528
23:         1979       44.45283          53  0.6116604
24:         1980       51.33333          45  0.6395556
25:         1981       51.20000          45  0.6677111
26:         1982       47.80851          47  0.6705745
27:         1983       42.55357          56  0.7012679
28:         1984       48.64815          54  0.6755185
29:         1985       40.46154          65  0.7196308
30:         1986       50.05556          72  0.6955417
31:         1987       36.12844         109  0.6350550
32:         1988       40.35294          85  0.6454235
33:         1989       44.08974          78  0.6550231
34:         1990       42.80247          81  0.6516914
35:         1991       38.70787          89  0.6743933
36:         1992       37.28409          88  0.6474659
37:         1993       38.81609          87  0.6679770
38:         1994       39.17073          82  0.6669024
39:         1995       37.00781         128  0.6582813
40:         1996       37.84211         114  0.6303070
41:         1997       39.68217         129  0.7040884
42:         1998       36.08088         136  0.7423088
43:         1999       43.38400         125  0.7390288
44:         2000       36.28859         149  0.7102148
45:         2001       37.68280         186  0.7078441
46:         2002       37.61765         170  0.6864525
47:         2003       36.37500         176  0.7010170
48:         2004       38.66857         175  0.7082629
49:         2005       30.91250         240  0.7182292
50:         2006       33.20321         187  0.6895882
51:         2007       32.03167         221  0.7046335
52:         2008       32.25574         305  0.7465705
53:         2009       31.95455         374  0.7561578
54:         2010       32.20896         335  0.7757433
55:         2011       33.42559         383  0.7296240
56:         2012       35.45299         351  0.7361425
57:         2013       31.26780         295  0.7019861
58:         2014       32.59850         401  0.6773738
59:         2015       32.12250         400  0.6740375
60:         2016       33.14550         378  0.6490534
61:         2017       36.43391         348  0.6564569
62:         2018       43.81609         261  0.6452682
63:         2019       48.44550         211  0.6600806
64:         2020       49.54688         256  0.6631406
65:         2021       41.00966         207  0.6741739
66:         2022       68.91667          60  0.7245000
67:         2023       76.78788          33  0.6893333
68:           NA       36.23457        1377         NA
    release_year avg_popularity track_count avg_energy
# Get top 5 most popular genres
genre_stats[order(-avg_popularity)][1:5]
         main_genre avg_popularity track_count avg_duration
             <char>          <num>       <int>        <num>
1: Reggae/Caribbean       48.22222          27     210.8963
2:              Pop       40.27116        5694     223.3444
3:             Rock       37.57563        2413     233.6300
4:         R&B/Soul       34.93709         302     227.6889
5:     Folk/Country       34.65934          91     205.5994

Chaining Operations

Data.table allows you to chain operations efficiently:

# Complex analysis chain
spotify_dt[popularity > 70
          ][, .(avg_energy = mean(energy),
                track_count = .N),
            by = main_genre
          ][order(-avg_energy)]
         main_genre avg_energy track_count
             <char>      <num>       <int>
1: Dance/Electronic  0.7640625          16
2:              Pop  0.6937229        1065
3:             Rock  0.6842514         395
4: Reggae/Caribbean  0.6568333           6
5:          Hip Hop  0.6486471          34
6:         R&B/Soul  0.6468684          38
7:            Other  0.6176429          28
8:     Folk/Country  0.5845833          12
  1. Special Symbols
  • .N: Counts rows (like n() in tidyverse)
  • .SD: Subset of data (useful for applying functions to multiple columns)
  • .(): Create a list (like select() or for multiple aggregations)
# Use .SD for multiple column operations
spotify_dt[, lapply(.SD, mean), 
          .SDcols = c("danceability", "energy", "valence"),
          by = main_genre]
                main_genre danceability    energy   valence
                    <char>        <num>     <num>     <num>
 1:       Dance/Electronic    0.6779331 0.8231969 0.5845252
 2:                    Pop    0.6243319 0.6954419 0.5665183
 3:                   Rock    0.5480435 0.6759753 0.5957726
 4:                Hip Hop    0.7607477 0.7146449 0.6088201
 5:                  Other           NA        NA        NA
 6:               R&B/Soul    0.6557980 0.6104570 0.6947848
 7:             Jazz/Blues    0.5241852 0.5895185 0.7212222
 8:           Folk/Country    0.5683407 0.5402066 0.5439121
 9:       Reggae/Caribbean    0.7564815 0.6411481 0.7690000
10: Classical/Instrumental    0.5580000 0.5570000 0.6500000

Performance Tips (Extra)

  1. set key columns for faster subsetting:

# Set key for faster lookups setkey(spotify_dt, main_genre) # Fast subset using key spotify_dt["Rock"]

# Set key for faster lookups 

setkey(spotify_dt, main_genre)  

# Fast subset using key 

spotify_dt["Rock"]
Key: <main_genre>
                                                   track_name
                                                       <char>
   1:                        Apeman - 2014 Remastered Version
   2:                      You Can't Always Get What You Want
   3:                              Don't Stop - 2004 Remaster
   4: Something About The Way You Look Tonight - Edit Version
   5:                                           Juke Box Hero
  ---                                                        
2409:                                     Blowin' in the Wind
2410:                                           She's My Baby
2411:                      Yellow Submarine - Remastered 2009
2412:                                     When You Were Young
2413:                                     Prisoner of Society
           artist_name_s
                  <char>
   1:          The Kinks
   2: The Rolling Stones
   3:      Fleetwood Mac
   4:         Elton John
   5:          Foreigner
  ---                   
2409:          Bob Dylan
2410:     Johnny O'Keefe
2411:        The Beatles
2412:        The Killers
2413:     The Living End
                                                                  album_name
                                                                      <char>
   1: Lola vs. Powerman and the Moneygoround, Pt. One + Percy (Super Deluxe)
   2:                                                           Let It Bleed
   3:                                                                Rumours
   4:                          Candle In The Wind 1997 / Something About ...
   5:                                                           4 (Expanded)
  ---                                                                       
2409:                                             The Freewheelin' Bob Dylan
2410:                                            The Very Best Of (Standard)
2411:                                                  Revolver (Remastered)
2412:                                                             Sam's Town
2413:                                                         The Living End
      album_artist_name_s album_release_date disc_number track_number
                   <char>             <char>       <int>        <int>
   1:           The Kinks         2014-10-20           1           11
   2:  The Rolling Stones         1969-12-05           1            9
   3:       Fleetwood Mac         1977-02-04           1            4
   4:          Elton John         1997-01-01           1            1
   5:           Foreigner               1981           1            2
  ---                                                                
2409:           Bob Dylan         1963-05-27           1            1
2410:      Johnny O'Keefe         2008-08-23           1            4
2411:         The Beatles         1966-08-05           1            6
2412:         The Killers         2006-10-03           1            3
2413:      The Living End         1999-01-15           1            1
      track_duration_ms explicit popularity         isrc
                  <int>   <lgcl>      <int>       <char>
   1:            233400    FALSE         42 GB5KW1499822
   2:            448720    FALSE          0 USA176910100
   3:            193346    FALSE         79 USWB10400049
   4:            240546    FALSE         61 GBAMS9700013
   5:            259800    FALSE         74 USAT20803006
  ---                                                   
2409:            165426    FALSE         71 USSM19900534
2410:            125226    FALSE         16 AUWA00800460
2411:            158880    FALSE         61 GBAYE0601498
2412:            220426    FALSE          1 USUM70605164
2413:            229066    FALSE         47 AUMPO9800004
                      added_by            added_at
                        <char>              <POSc>
   1: spotify:user:bradnumber1 2021-08-08 09:26:31
   2: spotify:user:bradnumber1 2021-08-08 09:26:31
   3: spotify:user:bradnumber1 2022-08-31 00:08:18
   4: spotify:user:bradnumber1 2021-08-08 09:26:31
   5: spotify:user:bradnumber1 2021-08-08 09:26:31
  ---                                             
2409: spotify:user:bradnumber1 2021-08-08 09:26:31
2410: spotify:user:bradnumber1 2021-08-08 09:26:31
2411: spotify:user:bradnumber1 2021-08-08 09:26:31
2412: spotify:user:bradnumber1 2021-08-08 09:26:31
2413: spotify:user:bradnumber1 2021-08-08 09:26:31
                                                                                                                artist_genres
                                                                                                                       <char>
   1: album rock,art rock,british invasion,classic rock,folk rock,glam rock,protopunk,psychedelic rock,rock,singer-songwriter
   2:                                                                           album rock,british invasion,classic rock,rock
   3:                                                                       album rock,classic rock,rock,soft rock,yacht rock
   4:                                                                                   glam rock,mellow gold,piano rock,rock
   5:                                  album rock,classic rock,glam metal,hard rock,heartland rock,mellow gold,rock,soft rock
  ---                                                                                                                        
2409:                                              classic rock,country rock,folk,folk rock,rock,roots rock,singer-songwriter
2410:                                                                                                         australian rock
2411:                                               beatlesque,british invasion,classic rock,merseybeat,psychedelic rock,rock
2412:                                                             alternative rock,dance rock,modern rock,permanent wave,rock
2413:                                                              australian alternative rock,australian rock,australian ska
      danceability energy   key loudness  mode speechiness acousticness
             <num>  <num> <int>    <num> <int>       <num>        <num>
   1:        0.683 0.7280     9   -8.920     1      0.2590     0.568000
   2:        0.319 0.6270     0   -9.611     1      0.0687     0.675000
   3:        0.671 0.7100     9   -7.724     1      0.0356     0.039300
   4:        0.480 0.6280     6   -7.643     1      0.0262     0.174000
   5:        0.357 0.6530     9   -5.554     1      0.0654     0.082800
  ---                                                                  
2409:        0.380 0.0993     2  -20.567     1      0.0509     0.914000
2410:        0.582 0.7720     2   -5.028     1      0.0332     0.691000
2411:        0.604 0.5490     1   -9.873     1      0.0389     0.531000
2412:        0.467 0.9880    11   -3.313     1      0.1120     0.000152
2413:        0.275 0.9930     9   -5.474     0      0.1380     0.000186
      instrumentalness liveness valence   tempo time_signature album_genres
                 <num>    <num>   <num>   <num>          <int>       <lgcl>
   1:         5.08e-05   0.0384   0.833  75.311              4           NA
   2:         7.29e-05   0.2890   0.497  85.818              4           NA
   3:         1.12e-05   0.0387   0.834 118.745              4           NA
   4:         3.28e-05   0.0753   0.541 143.412              4           NA
   5:         0.00e+00   0.0844   0.522 176.647              4           NA
  ---                                                                      
2409:         2.32e-05   0.0605   0.440 174.874              4           NA
2410:         1.75e-04   0.1240   0.731 131.613              4           NA
2411:         0.00e+00   0.4380   0.696 111.398              4           NA
2412:         4.84e-02   0.2800   0.321 130.435              4           NA
2413:         0.00e+00   0.3020   0.190 148.725              4           NA
                      label
                     <char>
   1:     Sanctuary Records
   2: Universal Music Group
   3:  Rhino/Warner Records
   4:                   EMI
   5:        Rhino Atlantic
  ---                      
2409:              Columbia
2410:          WM Australia
2411:         EMI Catalogue
2412: Universal Music Group
2413:               Reprise
                                                                                                                                       copyrights
                                                                                                                                           <char>
   1:                                  C © 2014 Sanctuary Records Group Ltd., a BMG Company, P ℗ 2014 Sanctuary Records Group Ltd., a BMG Company
   2:                                                                    C © 2002 ABKCO Music & Records Inc., P ℗ 2002 ABKCO Music & Records Inc.
   3:                                                                                  C © 2004 Warner Records Inc., P ℗ 2004 Warner Records Inc.
   4:                                                         C © 1997 Mercury Records Limited, P This Compilation ℗ 1997 Mercury Records Limited
   5: C © 2002 Atlantic Recording Corp., marketed by Rhino Entertainment Company, a Warner Music Group company, P ℗ 2002 Atlantic Recording Corp.
  ---                                                                                                                                            
2409:                                                                                    P Originally Released 1963 Sony Music Entertainment Inc.
2410:                                                    C © 2008 Warner Music Australia Pty Limited, P ℗ 2008 Warner Music Australia Pty Limited
2411:                                   C © 2015 Apple Corps Ltd., P ℗ 2015 Calderstone Productions Limited (a division of Universal Music Group)
2412:                                                            C © 2006 The Island Def Jam Music Group, P ℗ 2006 The Island Def Jam Music Group
2413:                                                                                    C © 1999 Reprise Records, P ℗ 1998, 1999 Reprise Records
      main_genre duration_sec popularity_scaled is_popular
          <char>        <num>             <num>     <lgcl>
   1:       Rock      233.400              0.42      FALSE
   2:       Rock      448.720              0.00      FALSE
   3:       Rock      193.346              0.79       TRUE
   4:       Rock      240.546              0.61      FALSE
   5:       Rock      259.800              0.74      FALSE
  ---                                                     
2409:       Rock      165.426              0.71      FALSE
2410:       Rock      125.226              0.16      FALSE
2411:       Rock      158.880              0.61      FALSE
2412:       Rock      220.426              0.01      FALSE
2413:       Rock      229.066              0.47      FALSE
      loudness_energy_ratio release_date release_year release_month release_day
                      <num>       <Date>        <num>         <num>       <int>
   1:            -12.252747   2014-10-20         2014            10          20
   2:            -15.328549   1969-12-05         1969            12           5
   3:            -10.878873   1977-02-04         1977             2           4
   4:            -12.170382   1997-01-01         1997             1           1
   5:             -8.505360         <NA>           NA            NA          NA
  ---                                                                          
2409:           -207.119839   1963-05-27         1963             5          27
2410:             -6.512953   2008-08-23         2008             8          23
2411:            -17.983607   1966-08-05         1966             8           5
2412:             -3.353239   2006-10-03         2006            10           3
2413:             -5.512588   1999-01-15         1999             1          15
  1. Avoid copies with :=:
# More efficient than creating new objects 
spotify_dt[, efficiency_ratio := energy/danceability]
  1. Use .SDcols for column operations:
# Efficient multiple column operations 
audio_features <- c("danceability", "energy", "valence") 

spotify_dt[, lapply(.SD, mean), .SDcols = audio_features, by = main_genre]
Key: <main_genre>
                main_genre danceability    energy   valence
                    <char>        <num>     <num>     <num>
 1: Classical/Instrumental    0.5580000 0.5570000 0.6500000
 2:       Dance/Electronic    0.6779331 0.8231969 0.5845252
 3:           Folk/Country    0.5683407 0.5402066 0.5439121
 4:                Hip Hop    0.7607477 0.7146449 0.6088201
 5:             Jazz/Blues    0.5241852 0.5895185 0.7212222
 6:                  Other           NA        NA        NA
 7:                    Pop    0.6243319 0.6954419 0.5665183
 8:               R&B/Soul    0.6557980 0.6104570 0.6947848
 9:       Reggae/Caribbean    0.7564815 0.6411481 0.7690000
10:                   Rock    0.5480435 0.6759753 0.5957726

Watch out for these common mistakes:

  • Forgetting the .() when selecting multiple columns
  • Using $ instead of := for assignments
  • Forgetting to add [] at the end when you want to see results

Remember:

  • tidyverse is great for readability and smaller datasets
  • data.table shines with big data and performance needs
  • Both have their place in your R toolkit

🎊🎉 Congratulations you finished week 4 and now on to a mini project analysis using data.table functions.

💡 Mini-Project Guidelines:

Create a comprehensive analysis using data.table that:

Demonstrates at least three different data.table operations Includes performance comparisons with equivalent dplyr operations Creates insightful visualizations from the results

Remember to:

  • Document your code

  • Explain your analysis choices

  • Consider performance implications

  • Think about scalability

Want more….

  • Explore more advanced data.table features

Prompt for Chat GPT/Claude/Gemini

You are a data scientist using exploring a large data set using exploratory data analysis principles. Your task is to create code in R using data.table functions to …. {Add what you want it to do}

Mini Project

To explore data.table and compare it to dplyr operations, I wanted to recreate my mini-project from last week. For my analysis, I will be comparing the danceability of songs across the decades. Like my previous analysis, I’m only including the pop and dance/electronic song genres because they seem to be the most “danceable” genres compared to the others.

# Filter the data to only include pop and dance/electronic songs
spotify_mini_proj_songs <- spotify_dt[main_genre == "Pop" 
                                      | main_genre == "Dance/Electronic"]

spotify_mini_proj_songs[, .(track_name, main_genre)]
Key: <main_genre>
                                                      track_name
                                                          <char>
   1:                    Justified & Ancient - Stand by the Jams
   2:                                                 Witchcraft
   3:                               Doin' The Do - 7"" Radio Mix
   4:                                                Do It Again
   5:                                                       Free
  ---                                                           
5944:                                         Baby Don't Hurt Me
5945:                               Kernkraft 400 (A Better Day)
5946: Groovejet (If This Ain't Love) [feat. Sophie Ellis-Bextor]
5947:                                                    Lay Low
5948:                                                Padam Padam
            main_genre
                <char>
   1: Dance/Electronic
   2: Dance/Electronic
   3: Dance/Electronic
   4: Dance/Electronic
   5: Dance/Electronic
  ---                 
5944:              Pop
5945:              Pop
5946:              Pop
5947:              Pop
5948:              Pop
# Sample the songs by proportion
spotify_mini_proj_sample <- spotify_mini_proj_songs %>%
  sample_frac(0.1)
# Create the release_date, release_year, and decade columns to help with comparison
# Modified from the 'Working with Dates' section above
library(lubridate)

# Convert and extract date components
spotify_mini_proj <- spotify_mini_proj_sample[, `:=`(
  release_date = as.Date(album_release_date),
  release_year = year(as.Date(album_release_date))
)]

spotify_mini_proj <- spotify_mini_proj[, `:=`(
  decade = floor(release_year / 10) * 10
)]
Warning in `[.data.table`(spotify_mini_proj, , `:=`(decade =
floor(release_year/10) * : Invalid .internal.selfref detected and fixed by
taking a (shallow) copy of the data.table so that := can add this new column by
reference. At an earlier point, this data.table has been copied by R (or was
created manually using structure() or similar). Avoid names<- and attr<- which
in R currently (and oddly) may copy the whole data.table. Use set* syntax
instead to avoid copying: ?set, ?setnames and ?setattr. If this message doesn't
help, please report your use case to the data.table issue tracker so the root
cause can be fixed or this message improved.
# Check results
spotify_mini_proj[, .(track_name, release_year, decade)]
                                                                                     track_name
                                                                                         <char>
  1:                                                              Lifestyle (feat. Adam Levine)
  2:                                                            #WHERESTHELOVE - Charity Single
  3:                                                                     Song 2 - 2012 Remaster
  4:                                                                                       Cars
  5:                                                                         Where Is The Love?
 ---                                                                                           
591: Wanna Be Startin' Somethin' (2008 with Akon) (with Akon) - Thriller 25th Anniversary Remix
592:                                                                            Chasing The Sun
593:                                                                                       Maps
594:                                                                              Eternal Flame
595:                                                                       Don’t Stop The Party
     release_year decade
            <num>  <num>
  1:         2021   2020
  2:         2016   2010
  3:         1997   1990
  4:           NA     NA
  5:           NA     NA
 ---                    
591:         2008   2000
592:         2012   2010
593:         2015   2010
594:           NA     NA
595:         2010   2010
# Group the data by decade and calculate the mean danceability score
# Arrange the data in descending order, omitting any black values from display
na.omit(spotify_mini_proj[, .(
  avg_danceability = mean(danceability, na.rm = TRUE)
), by = decade][
  order(-avg_danceability)])
   decade avg_danceability
    <num>            <num>
1:   2020        0.6982821
2:   1980        0.6701290
3:   2010        0.6448918
4:   1970        0.6317000
5:   2000        0.6206739
6:   1990        0.5981719
7:   1960        0.5631818

Comparison

To directly compare the data.table and dplyr, I want to compare the filtering, grouping, and calculating functions with the full dataset, instead of just the sample

# Filtering with data.table
system.time(spotify_dt[main_genre == "Pop" | main_genre == "Dance/Electronic"])
   user  system elapsed 
   0.00    0.00    0.01 
# Filtering with dplyr
system.time(filter(spotify_dt, 
                   main_genre == "Pop" | main_genre == "Dance/Electronic"))
   user  system elapsed 
   0.01    0.00    0.00 
# Grouping and calculating with data.table
system.time(
  spotify_dt[, .(
  avg_danceability = mean(danceability, na.rm = TRUE),
  avg_energy = mean(energy, na.rm = TRUE),
  avg_loudness = mean(loudness, na.rm = TRUE)
), by = main_genre])
   user  system elapsed 
   0.01    0.00    0.00 
# Grouping and calculating with dplyr
system.time(spotify_dt %>%
              group_by(main_genre) %>%
              summarise(avg_danceability = mean(danceability, na.rm = TRUE),
                        avg_energy = mean(energy, na.rm = TRUE),
                        avg_loudness = mean(loudness, na.rm = TRUE)))
   user  system elapsed 
   0.01    0.00    0.02 

This brief performance comparison shows that, for more computationally expensive operations, data.table is more efficient than dplyr. For something like filtering, both libraries perform about the same. But for grouping and calculating multiple new columns, data.table beats dplyr by a few milliseconds. This shows that data.table functions have better performance implications. A data scientist working with big data or doing very complex computations might choose data.table over dplyr for its efficiency.

AI Usage

Prompt: You are a data scientist exploring a large data set using exploratory data analysis principles. Your task is to create code in R using data.table functions to find the songs where track_name is the same as album_name and where the track_name and album_name are different. Compare the popularity of the two groups to see whether there is a trend.

Resulting Code from ChatGPT:

# Group 1: Filter songs where track_name is the same as album_name
same_name_songs <- spotify_dt[track_name == album_name]

# Group 2: Filter songs where track_name is different from album_name
different_name_songs <- spotify_dt[track_name != album_name]

# Calculate average popularity for both groups
popularity_comparison <- data.table(
  group = c("Same Name", "Different Name"),
  average_popularity = c(
    mean(same_name_songs$popularity, na.rm = TRUE),
    mean(different_name_songs$popularity, na.rm = TRUE)
  )
)

# View the comparison of average popularity
print(popularity_comparison)
            group average_popularity
           <char>              <num>
1:      Same Name           38.02957
2: Different Name           37.55639
# Optional: Visualize the comparison using ggplot2
library(ggplot2)

# Create a bar plot to compare the popularity of the two groups
ggplot(popularity_comparison, aes(x = group, y = average_popularity, fill = group)) +
  geom_bar(stat = "identity", show.legend = FALSE) +
  labs(title = "Comparison of Popularity: Same Name vs. Different Name Tracks",
       x = "Group", y = "Average Popularity") +
  theme_minimal()

Explanation of the Code from ChatGPT:

  1. Filter the Groups:

    • Group 1 (same_name_songs): We filter the songs where track_name is equal to album_name using the expression track_name == album_name.

    • Group 2 (different_name_songs): We filter the songs where track_name is different from album_name using the expression track_name != album_name.

  2. Average Popularity:

    • We calculate the average popularity for both groups using the mean function and store the results in a new data.table called popularity_comparison.
  3. Visualization:

    • A bar plot is created using ggplot2 to visually compare the average popularity between the two groups.
  4. Trend Analysis:

    • The comparison will show if there’s a significant difference in the average popularity between the two groups. If you notice that one group consistently has higher or lower popularity, it could indicate a trend.