Re: [R] Purr and Basic Functional Programming Tasks

2019-01-27 Thread Lorenzo Isella
Dear Jim, Thanks a lot for your stellar replies! They address my questions perfectly. Cheers Lorenzo On Fri, Jan 25, 2019 at 07:46:50AM -0800, jim holtman wrote: Try this for the second question: years <- map2(zz, + list(c(2000, 2001), c(2001, 2003)), + ~ filter(

Re: [R] Purr and Basic Functional Programming Tasks

2019-01-25 Thread jim holtman
Try this for the second question: > years <- map2(zz, + list(c(2000, 2001), c(2001, 2003)), + ~ filter(.x, year %in% .y) + ) > years [[1]] # A tibble: 6 x 4 year tot_i relation g_rate 1 2000 22393349. EU28-Algeria 0.736 2

Re: [R] Purr and Basic Functional Programming Tasks

2019-01-25 Thread jim holtman
Does this answer the first question? > rel <- map(zz, function(x){ + group_by(x, relation) %>% summarise(tot = mean(tot_i)) + }) > rel [[1]] # A tibble: 3 x 2 relation tot 1 EU28-Algeria 22186767. 2 Extra EU28-Algeria 12884156. 3 World-Algeria 35

[R] Purr and Basic Functional Programming Tasks

2019-01-25 Thread Lorenzo Isella
Dear All, I am making my baby steps with the tidyverse purr package and I am stuck with some probably trivial tasks. Consider the following data set zz<-list(structure(list(year = c(2000, 2001, 2002, 2003, 2000, 2001, 2002, 2003, 2000, 2001, 2002, 2003), tot_i = c(22393349.081, 23000574.372, 2