Closed basteln3rk closed 6 years ago
I've fixed this in the dev version. We now add ..1
rather than .1
to separate out duplicate names. Thanks!
library(tidyquant)
FANG %>%
group_by(symbol) %>%
select(symbol, date, adjusted) %>%
tq_mutate(adjusted, lag.xts, k = 1:2)
#> # A tibble: 4,032 x 5
#> # Groups: symbol [4]
#> symbol date adjusted lag.xts lag.xts..1
#> <chr> <date> <dbl> <dbl> <dbl>
#> 1 FB 2013-01-02 28.0 NA NA
#> 2 FB 2013-01-03 27.8 28.0 NA
#> 3 FB 2013-01-04 28.8 27.8 28.0
#> 4 FB 2013-01-07 29.4 28.8 27.8
#> 5 FB 2013-01-08 29.1 29.4 28.8
#> 6 FB 2013-01-09 30.6 29.1 29.4
#> 7 FB 2013-01-10 31.3 30.6 29.1
#> 8 FB 2013-01-11 31.7 31.3 30.6
#> 9 FB 2013-01-14 31.0 31.7 31.3
#> 10 FB 2013-01-15 30.1 31.0 31.7
#> # ... with 4,022 more rows
Created on 2018-03-07 by the reprex package (v0.1.1.9000).
When the original variable name contains a dot, then after
tq_mutate
, the new variable name is broken! Moreover, the way the naming is broken is potentially quite confusing and may lead the analyst to make errors...Minimum Working Example:
v.var
becomes calledv.1
(should have been called:v.var.1
)v.var.1
(should have been calledv.var.2
)Session info: