search for: group_modify

Displaying 3 results from an estimated 3 matches for "group_modify".

2024 May 24
1
dplyr, group_by and selective action according to each group
...s, but I am not able to write it in a more esthetic way using dplyr. Can somebody help me to find a better solution ? Thank you Best regards Laurent df_test <- data.frame( x1=1:9, x2=1:9, gr=rep(paste0("gr",1:3),each=3)) df_test? <-? df_test %>% dplyr::group_by(gr) %>% ? group_modify(.f=function(.x,.y){ ??? print(paste0("Nom du groupe : ",.y[["gr"]])) ??? switch(as.character(.y[["gr"]]) ?????????? , gr1 = {.x[,"x1"] <- .x[,"x1"]+1} ?????????? , gr2 = {.x[,"x1"] <- 0} ?????????? , gr3 = {.x[,"x1"] &...
2024 May 24
1
dplyr, group_by and selective action according to each group
...c way using > dplyr. Can somebody help me to find a better solution ? > > Thank you > > Best regards > > Laurent > > df_test <- data.frame( x1=1:9, x2=1:9, gr=rep(paste0("gr",1:3),each=3)) > df_test <- df_test %>% dplyr::group_by(gr) %>% > group_modify(.f=function(.x,.y){ > print(paste0("Nom du groupe : ",.y[["gr"]])) > switch(as.character(.y[["gr"]]) > , gr1 = {.x[,"x1"] <- .x[,"x1"]+1} > , gr2 = {.x[,"x1"] <- 0} > , gr3...
2024 May 25
1
dplyr, group_by and selective action according to each group
...c way using > dplyr. Can somebody help me to find a better solution ? > > Thank you > > Best regards > > Laurent > > df_test <- data.frame( x1=1:9, x2=1:9, gr=rep(paste0("gr",1:3),each=3)) > df_test <- df_test %>% dplyr::group_by(gr) %>% > group_modify(.f=function(.x,.y){ > print(paste0("Nom du groupe : ",.y[["gr"]])) > switch(as.character(.y[["gr"]]) > , gr1 = {.x[,"x1"] <- .x[,"x1"]+1} > , gr2 = {.x[,"x1"] <- 0} > , gr3...