-
Notifications
You must be signed in to change notification settings - Fork 0
/
Why_I_love_datatable.Rmd
120 lines (70 loc) · 1.88 KB
/
Why_I_love_datatable.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
title: "Why I love data.table"
author: "Chris Mainey"
date: '`r Sys.Date()`'
output:
xaringan::moon_reader:
lib_dir: libs
css: xaringan-themer.css
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
seal: false
---
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
```{r xaringan-themer, include=FALSE}
library(xaringanthemer)
mono_light(base_color = "#23395b",
)
```
.pull-left[
<br><br><br>
<br><br><br>
# Why I love
<br><br><br>
<br><br><br>
`r icon::fa("envelope")` chris.mainey@uhb.nhs.uk
`r icon::fa("globe")` [mainard.co.uk](https://www.mainard.co.uk)
`r icon::fa("github")` [github.com/chrismainey](https://github.com/chrismainey)
`r icon::fa("twitter")` [twitter.com/chrismainey](https://twitter.com/chrismainey)
]
.pull-right[
<br><br><br>
<br>
![](https://raw.githubusercontent.com/Rdatatable/data.table/master/.graphics/logo.png)]
---
# What is it?
+ Modern reworking of `data.frame`
+ Implemented in C for speed and portability
+ Using Low level paralellism via OpenMP
+ Supports keys, to physiscally order data in memory
--
# Why?
+ `data.frame` is slow, `data.table` is fast:
--
+ Like, _reeeeeally fast_ : https://h2oai.github.io/db-benchmark/
--
+ Pass by reference, not by value.
--
+ It uses minimal memory
--
+ Fast I/O functions: `fread` and `fwrite`
---
# Synatx overview
<br><br>
![](https://www.meganstodel.com/posts/2019-05-30-three-reasons-why-i-use-data-table_files/datatable.png)
.footnote[
Image taken from `data.table` wiki, via Megan Stodel's excellent blog post: https://www.meganstodel.com/posts/data-table/
]
---
# Examples
```{r dt_example}
library(NHSRdatasets)
library(data.table)
dt<-data.table(LOS_model, key = "Organisation")
dt[Organisation == "Trust1", median(LOS)]
dt[,.(Mean = mean(LOS), Median=median(LOS)), Organisation]
```