Last active
May 11, 2017 12:52
-
-
Save yutannihilation/4f86c8d22863edc5d06778bac085edd7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Rのコピー修正の例 | |
| ## 元のデータを上書きしない場合 | |
| ### `mutate()` | |
| ``` r | |
| library(pryr) | |
| library(dplyr, warn.conflicts = FALSE) | |
| d <- tibble(x = 1:1000000, y = 1:1000000) | |
| mem_change(x <- d %>% mutate(z = x * 2)) | |
| #> 8.18 MB | |
| mem_used() | |
| #> 59.5 MB | |
| ``` | |
| ### `transmute()` | |
| ``` r | |
| library(pryr) | |
| library(dplyr, warn.conflicts = FALSE) | |
| d <- tibble(x = 1:1000000, y = 1:1000000) | |
| mem_change(x <- d %>% transmute(z = x * 2)) | |
| #> 8.28 MB | |
| mem_used() | |
| #> 59.6 MB | |
| ``` | |
| ## 元のデータを上書きする場合 | |
| ### `mutate()` | |
| ``` r | |
| library(pryr) | |
| library(dplyr, warn.conflicts = FALSE) | |
| d <- tibble(x = 1:1000000, y = 1:1000000) | |
| mem_change(d <- d %>% mutate(z = x * 2)) | |
| #> 8.18 MB | |
| mem_used() | |
| #> 59.5 MB | |
| ``` | |
| ### `transmute()` | |
| ``` r | |
| library(pryr) | |
| library(dplyr, warn.conflicts = FALSE) | |
| d <- tibble(x = 1:1000000, y = 1:1000000) | |
| mem_change(d <- d %>% transmute(z = x * 2)) | |
| #> 276 kB | |
| mem_used() | |
| #> 51.6 MB | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment