91 lines
2.2 KiB
Org Mode
91 lines
2.2 KiB
Org Mode
#+TITLE: Datatable package
|
|
#+DATE: 2021-10-26
|
|
#+OPTIONS: creator:nil timestamp:nil todo:nil num:nil
|
|
#+PROPERTY: header-args:R :results output :session *Rc* :cmdline :tangle yes
|
|
#+PROPERTY: header-args:R+ :exports both
|
|
#+SETUPFILE: https://fniessen.github.io/org-html-themes/org/theme-readtheorg.setup
|
|
#+HTML_HEAD: <style> #content{max-width:1800px;}</style>
|
|
#+HTML_HEAD: <style> p{max-width:800px;}</style>
|
|
#+HTML_HEAD: <style> li{max-width:800px;}</style>
|
|
#+HTML_HEAD: <style> pre.src{background: #f5f5f5;color:black;}</style>
|
|
#+HTML_HEAD: <style> .example{background: #fefefa;color:black;}</style>
|
|
|
|
|
|
#+begin_export html
|
|
<div id="subtitle" style="float: center; text-align: center;">
|
|
<p>
|
|
Org document with
|
|
<a href="http://www.r-project.org/">R</a> code
|
|
</p>
|
|
<p>
|
|
<a href="http://www.r-project.org/">
|
|
<img src="http://www.r-project.org/Rlogo.jpg"/>
|
|
</a>
|
|
</p>
|
|
</div>
|
|
#+end_export
|
|
|
|
#+begin_src R :exports code
|
|
rm(list = ls())
|
|
#+end_src
|
|
|
|
** Introduction
|
|
|
|
#+begin_src R
|
|
library(data.table)
|
|
#+end_src
|
|
|
|
|
|
Reading data into R using ~{data.table}~
|
|
|
|
#+begin_src R :exports code
|
|
url = "https://raw.githubusercontent.com/Rdatatable/data.table/master/vignettes/flights14.csv"
|
|
flights <- fread(url)
|
|
#+end_src
|
|
|
|
#+RESULTS:
|
|
|
|
#+begin_src R
|
|
names(flights)
|
|
#+end_src
|
|
|
|
#+begin_src R
|
|
flights
|
|
#+end_src
|
|
|
|
#+begin_src R
|
|
nrow(flights)
|
|
#+end_src
|
|
|
|
#+RESULTS:
|
|
: [1] 253316
|
|
|
|
Creating a data.table:
|
|
|
|
#+begin_src R
|
|
dt <- data.table(col1 = c(1:6),
|
|
col2 = LETTERS[1:6],
|
|
col3 = (1))
|
|
#+end_src
|
|
|
|
|
|
#+begin_src R
|
|
class(dt)
|
|
#+end_src
|
|
|
|
#+begin_src R
|
|
class(dt$col2)
|
|
#+end_src
|
|
|
|
** Some references to learn more about {data.table}
|
|
|
|
* https://cran.r-project.org/web/packages/data.table/vignettes/datatable-intro.html
|
|
* See vignettes in R:
|
|
: > vignette(package="data.table")
|
|
* https://atrebas.github.io/post/2019-03-03-datatable-dplyr/
|
|
* https://rdatatable.gitlab.io/data.table/
|
|
* https://s3.amazonaws.com/assets.datacamp.com/blog_assets/datatable_Cheat_Sheet_R.pdf
|
|
* https://stackoverflow.com/questions/21435339/data-table-vs-dplyr-can-one-do-something-well-the-other-cant-or-does-poorly
|
|
* ~dtplyr~ package:
|
|
* https://github.com/tidyverse/dtplyr
|