Re: [R] Can I pass the grouped portions of a dataframe/tibble to a function in dplyr

2020-07-05 Thread Chris Evans
Ouch. I should have know all those points Rui: my bad. Casual behaviour while just rushing up a little example. Good to be reminded. group_modify() is clearly exactly what I wanted and I will experiment with it and make sure I understand it properly. I see from the help that it evolves

Re: [R] Can I pass the grouped portions of a dataframe/tibble to a function in dplyr

2020-07-05 Thread Rui Barradas
Hello, I forgot to say I redid the data set setting the RNG seed first. set.seed(2020) n <- 50 x <- 1:n y <- sample(1:3, n, replace = TRUE) z <- rnorm(n) tib <- tibble(x,y,z) Also, don't do as_tibble(cbind(...)) as.data.frame(cbind(...)) If one of the variables is of a different class

Re: [R] Can I pass the grouped portions of a dataframe/tibble to a function in dplyr

2020-07-05 Thread Rui Barradas
Hello, You can pass a grouped tibble to a function with grouped_modify but the function must return a data.frame (or similar). ## this will also do it #sillyFun <- function(tib){ # tibble(nrow = nrow(tib), ncol = ncol(tib)) #} sillyFun <- function(tib){ data.frame(nrow = nrow(tib), ncol