{"action":"created","issue":{"url":"https://api.github.com/repos/haozhu233/kableExtra/issues/193","repository_url":"https://api.github.com/repos/haozhu233/kableExtra","labels_url":"https://api.github.com/repos/haozhu233/kableExtra/issues/193/labels{/name}","comments_url":"https://api.github.com/repos/haozhu233/kableExtra/issues/193/comments","events_url":"https://api.github.com/repos/haozhu233/kableExtra/issues/193/events","html_url":"https://github.com/haozhu233/kableExtra/issues/193","id":320244995,"number":193,"title":"auto index for group_rows","user":{"login":"larmarange","id":966307,"avatar_url":"https://avatars1.githubusercontent.com/u/966307?v=4","gravatar_id":"","url":"https://api.github.com/users/larmarange","html_url":"https://github.com/larmarange","followers_url":"https://api.github.com/users/larmarange/followers","following_url":"https://api.github.com/users/larmarange/following{/other_user}","gists_url":"https://api.github.com/users/larmarange/gists{/gist_id}","starred_url":"https://api.github.com/users/larmarange/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/larmarange/subscriptions","organizations_url":"https://api.github.com/users/larmarange/orgs","repos_url":"https://api.github.com/users/larmarange/repos","events_url":"https://api.github.com/users/larmarange/events{/privacy}","received_events_url":"https://api.github.com/users/larmarange/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-05-04T11:46:02Z","updated_at":"2018-05-22T15:31:31Z","closed_at":null,"author_association":"NONE","body":"When working with categorical variables and presenting bivariate or multivariate statistics, I usually have several rows per variable. In my tables, I have therefore o column indicating the variable and a second for the considered term or modality.\r\n\r\nAn option is to use `collapse_rows`. However, I usually find that `group_rows` provide a more readable result. However, it requires to manually compute the index named vector indicator how to group rows. It would be much easier to have an automatic ways of generating this index.\r\n\r\nI'm using the following trick:\r\n\r\n```r\r\nauto_index_group_rows <- function(x) {\r\n  lx <- dplyr::lead(x)\r\n  \r\n  index <- c()\r\n  name <- c()\r\n  n <- 0\r\n  for (i in 1:length(x)) {\r\n    n <- n + 1\r\n    if (!identical(x[i], lx[i]) | i == length(x)) {\r\n      index <- c(index, n)\r\n      name <- c(name, x[i])\r\n      n <- 0\r\n    }\r\n  }\r\n  names(index) <- name\r\n  index\r\n}\r\n```\r\n\r\n```\r\n> x <- c(\"a\", \"a\", \"a\", \"b\", \"b\", \"a\", \"c\", \"c\")\r\n> auto_index_group_rows(x)\r\na b a c \r\n3 2 1 2 \r\n```\r\n\r\nallowing to generate automatically the index vector: `group_rows(index = auto_index_group_rows(tab$var))`\r\n\r\nI would wonder if such similar features would be relevant to be implemented directly in `kableExtra`?"},"comment":{"url":"https://api.github.com/repos/haozhu233/kableExtra/issues/comments/391035479","html_url":"https://github.com/haozhu233/kableExtra/issues/193#issuecomment-391035479","issue_url":"https://api.github.com/repos/haozhu233/kableExtra/issues/193","id":391035479,"user":{"login":"larmarange","id":966307,"avatar_url":"https://avatars1.githubusercontent.com/u/966307?v=4","gravatar_id":"","url":"https://api.github.com/users/larmarange","html_url":"https://github.com/larmarange","followers_url":"https://api.github.com/users/larmarange/followers","following_url":"https://api.github.com/users/larmarange/following{/other_user}","gists_url":"https://api.github.com/users/larmarange/gists{/gist_id}","starred_url":"https://api.github.com/users/larmarange/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/larmarange/subscriptions","organizations_url":"https://api.github.com/users/larmarange/orgs","repos_url":"https://api.github.com/users/larmarange/repos","events_url":"https://api.github.com/users/larmarange/events{/privacy}","received_events_url":"https://api.github.com/users/larmarange/received_events","type":"User","site_admin":false},"created_at":"2018-05-22T15:31:31Z","updated_at":"2018-05-22T15:31:31Z","author_association":"NONE","body":"Thanks a lot"}}
{"actor":{"display_login":"larmarange"}}