{"id":341,"date":"2020-04-21T02:57:07","date_gmt":"2020-04-21T09:57:07","guid":{"rendered":"https:\/\/blogs.ubc.ca\/khead\/?p=341"},"modified":"2020-09-02T17:48:02","modified_gmt":"2020-09-03T00:48:02","slug":"10-places-to-get-started-with-data-table","status":"publish","type":"post","link":"https:\/\/blogs.ubc.ca\/khead\/10-places-to-get-started-with-data-table","title":{"rendered":"10 places to get started with data.table"},"content":{"rendered":"<p>A drawback of R compared to Stata and, within R, of data.table compared to tidyverse, is that documentation is spread out all over the place. You end up doing a lot of googling and spending time at Stack overflow. The problem is many R users now think the tidyverse and dplyr in particular is all there is. I started with base R and it is still what i use for many things. But when I began to switch my data &#8220;wrangling&#8221; from Stata to R, I got started on dplyr, only to learn (from Julian Hinz) that data.table is much faster. After initial struggles I realized that the syntax of data.table fit much better with my intuitions of the right way to do things. I am in the minority on this topic but not alone. In an effort to convince more people to take advantage of the powerful syntax and awesome speed of data.table, I am posting this set of resources.<\/p>\n<p>PS. This now goes to 11! Here&#8217;s a great set of lecture slides from Grant McDermott. If you don&#8217;t follow him already, you should.<\/p>\n<p><a href=\"https:\/\/raw.githack.com\/uo-ec510-2020-spring\/lectures\/master\/05-datatable\/05-datatable.html#1\">https:\/\/raw.githack.com\/uo-ec510-2020-spring\/lectures\/master\/05-datatable\/05-datatable.html#1<\/a><\/p>\n<p>These items are not ordered for beginners. I started with number 8 (which, as the title suggests, was probably not optimal!). But 4 and then 3 might be ideal starting points. According to my notes 9 (and its sequels) are good starting places.<\/p>\n<ol>\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/21435339\/data-table-vs-dplyr-can-one-do-something-well-the-other-cant-or-does-poorly\">https:\/\/stackoverflow.com\/questions\/21435339\/data-table-vs-dplyr-can-one-do-something-well-the-other-cant-or-does-poorly<\/a> This is not actually a good starting point at all but if you&#8217;re already a dplyr user you might look at this to decide how interested you might be in data.table<\/li>\n<li><a href=\"https:\/\/atrebas.github.io\/post\/2019-03-03-datatable-dplyr\/\">https:\/\/atrebas.github.io\/post\/2019-03-03-datatable-dplyr\/<\/a> Comprehensive correspondence between dplyr and data.table ways to do things<\/li>\n<li><a href=\"https:\/\/github.com\/chuvanan\/rdatatable-cookbook\">https:\/\/github.com\/chuvanan\/rdatatable-cookbook<\/a>. Here&#8217;s a set of chapters showing how to do common tasks in data.table.<\/li>\n<li><a href=\"https:\/\/github.com\/Rdatatable\/data.table\/wiki\/\/talks\/useR2019_Arun.pdf\">https:\/\/github.com\/Rdatatable\/data.table\/wiki\/\/talks\/useR2019_Arun.pdf<\/a> Great slides introduce data.table&#8217;s three key components.<br \/>\nAlso illustrates .SD with patterns, a very powerful method.<\/li>\n<li>\u00a0Frequently Asked Questions: <a href=\"http:\/\/datatable.r-forge.r-project.org\/datatable-faq.pdf\">http:\/\/datatable.r-forge.r-project.org\/datatable-faq.pdf<\/a><\/li>\n<li>The cheat sheet to print out and and pin to the wall somewhere nearby. <a href=\"https:\/\/s3.amazonaws.com\/assets.datacamp.com\/blog_assets\/datatable_Cheat_Sheet_R.pdf\">https:\/\/s3.amazonaws.com\/assets.datacamp.com\/blog_assets\/datatable_Cheat_Sheet_R.pdf<\/a><\/li>\n<li>Many posts have shown how much faster data.table is than the alternatives. This one compares with dplyr, base R, and Python Pandas. <a href=\"https:\/\/github.com\/szilard\/benchm-dplyr-dt\">https:\/\/github.com\/szilard\/benchm-dplyr-dt<\/a> And here is some code showing how they did each task in data.table compared to dplyr: <a href=\"https:\/\/github.com\/szilard\/benchm-dplyr-dt\/blob\/master\/bm.Rmd\">https:\/\/github.com\/szilard\/benchm-dplyr-dt\/blob\/master\/bm.Rmd<\/a><\/li>\n<li><a href=\"http:\/\/brooksandrew.github.io\/simpleblog\/articles\/advanced-data-table\/\">http:\/\/brooksandrew.github.io\/simpleblog\/articles\/advanced-data-table\/<\/a> Advanced tips and tricks with data.table<\/li>\n<li><a href=\"https:\/\/www.r-bloggers.com\/data-table-by-example-part-1\/\">https:\/\/www.r-bloggers.com\/data-table-by-example-part-1\/<\/a><\/li>\n<li><a href=\"https:\/\/cran.r-project.org\/web\/packages\/data.table\/vignettes\/datatable-reference-semantics.html\">https:\/\/cran.r-project.org\/web\/packages\/data.table\/vignettes\/datatable-reference-semantics.html<\/a> Explains about &#8220;modifying by reference&#8221; which is one of the trickiest topics and most important to understand. Here you will see why &#8220;DT &lt;- copy(DT)&#8221;\u00a0 will be an essential line in your functions to avoid unwanted side-effects. More discussion here:\u00a0<a href=\"https:\/\/stackoverflow.com\/questions\/13756178\/writings-functions-procedures-for-data-table-objects\">https:\/\/stackoverflow.com\/questions\/13756178\/writings-functions-procedures-for-data-table-objects<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>A drawback of R compared to Stata and, within R, of data.table compared to tidyverse, is that documentation is spread out all over the place. You end up doing a lot of googling and spending time at Stack overflow. The problem is many R users now think the tidyverse and dplyr in particular is all [&hellip;]<\/p>\n","protected":false},"author":32530,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[369518],"tags":[],"class_list":["post-341","post","type-post","status-publish","format-standard","hentry","category-r-data-table"],"_links":{"self":[{"href":"https:\/\/blogs.ubc.ca\/khead\/wp-json\/wp\/v2\/posts\/341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ubc.ca\/khead\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.ubc.ca\/khead\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/khead\/wp-json\/wp\/v2\/users\/32530"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ubc.ca\/khead\/wp-json\/wp\/v2\/comments?post=341"}],"version-history":[{"count":5,"href":"https:\/\/blogs.ubc.ca\/khead\/wp-json\/wp\/v2\/posts\/341\/revisions"}],"predecessor-version":[{"id":343,"href":"https:\/\/blogs.ubc.ca\/khead\/wp-json\/wp\/v2\/posts\/341\/revisions\/343"}],"wp:attachment":[{"href":"https:\/\/blogs.ubc.ca\/khead\/wp-json\/wp\/v2\/media?parent=341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.ubc.ca\/khead\/wp-json\/wp\/v2\/categories?post=341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.ubc.ca\/khead\/wp-json\/wp\/v2\/tags?post=341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}