/
inspect_mem_examples.Rmd
82 lines (56 loc) · 2.02 KB
/
inspect_mem_examples.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
---
title: "Memory usage of dataframe columns"
output: github_document
---
Illustrative data: `starwars`
---
The examples below make use of the `starwars` and `storms` data from the `dplyr` package
```{r}
# some example data
data(starwars, package = "dplyr")
data(storms, package = "dplyr")
```
For illustrating comparisons of dataframes, use the `starwars` data and produce two new dataframes `star_1` and `star_2` that randomly sample the rows of the original and drop a couple of columns.
---
title: "Missingness and counting NAs"
output: github_document
---
```{r, message=FALSE, warning=FALSE}
library(dplyr)
star_1 <- starwars %>% sample_n(50)
star_2 <- starwars %>% sample_n(50) %>% select(-1, -2)
```
Illustrative data: `starwars`
---
The examples below make use of the `starwars` and `storms` data from the `dplyr` package
```{r}
# some example data
data(starwars, package = "dplyr")
data(storms, package = "dplyr")
```
For illustrating comparisons of dataframes, use the `starwars` data and produce two new dataframes `star_1` and `star_2` that randomly sample the rows of the original and drop a couple of columns.
```{r, message=FALSE, warning=FALSE}
library(dplyr)
star_1 <- starwars %>% sample_n(50)
star_2 <- starwars %>% sample_n(50) %>% select(-1, -2)
```
`inspect_mem()` for a single dataframe
---
To explore the memory usage of the columns in a data frame, use `inspect_mem()`. The command returns a `tibble` containing the size of each column in the dataframe.
```{r}
library(inspectdf)
inspect_mem(starwars)
```
A barplot can be produced by passing the result to `show_plot()`:
```{r}
inspect_mem(starwars) %>% show_plot()
```
`inspect_mem()` for two dataframes
---
When a second dataframe is provided, `inspect_mem()` will create a dataframe comparing the size of each column for both input dataframes. The summaries for the first and second dataframes are show in columns with names appended with `_1` and `_2`, respectively.
```{r}
inspect_mem(star_1, star_2)
```
```{r}
inspect_mem(star_1, star_2) %>% show_plot()
```