Created
April 12, 2019 10:03
-
-
Save agila5/1880071f01228cf4ea3686677e1882e5 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 | |
# packages | |
library(dplyr) | |
#> | |
#> Attaching package: 'dplyr' | |
#> The following objects are masked from 'package:stats': | |
#> | |
#> filter, lag | |
#> The following objects are masked from 'package:base': | |
#> | |
#> intersect, setdiff, setequal, union | |
library(rlang) | |
# data | |
fake_data <- tibble( | |
A = 1 | |
) | |
# loop | |
for(i in 1:10) { | |
var_name <- paste0("X", i) | |
fake_data <- fake_data %>% | |
mutate(!!var_name := 1) | |
} | |
# show result | |
fake_data | |
#> # A tibble: 1 x 11 | |
#> A X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 | |
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> | |
#> 1 1 1 1 1 1 1 1 1 1 1 1 | |
``` | |
<sup>Created on 2019-04-12 by the [reprex package](https://reprex.tidyverse.org) (v0.2.1)</sup> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment