How can I reference the current data.frame in a dpylr flow? As an example, in
library(dplyr)
myresults = tribble(
~dataset_name, ~method_group, ~method, ~value,
'iris', 'other', 'a', 1,
'wine', 'other', 'b', 2,
'iris', 'mine', 'c', 3,
'wine', 'mine', 'd', 4
)
myresults %>%
mutate(dataset_name='datasets aggregated') %>%
bind_rows(XXX %>% filter(method=='c') %>% mutate(method_group = 'other'))
I would like to row-bind the current data.frame with itself. What do I write instead of the XXX ?
In the function do()
, the answer seems to be .
. Even though this is not very elegant and I would prefer not to have to use do, I managed to get the desired result with
myresults %>%
mutate(dataset_name='datasets aggregated') %>%
do(bind_rows(data.frame(.), data.frame(.) %>% filter(method=='c') %>% mutate(method_group = 'other')))
but this is not very nice.
My R version is:
> R.version
_
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 3
minor 4.4
year 2018
month 03
day 15
svn rev 74408
language R
version.string R version 3.4.4 (2018-03-15)
nickname Someone to Lean On