how can i create a group in r?

Using janitor and tidyverse

library(tidyverse)
library(janitor)
test_data <- tibble(x=1:10,y=11:20, room=c("a","b","a","b","a","b","a","b","a","b"), colour=c("red","blue","green","black","red","red","blue","green","black","red"))

test_data %>%
    group_by(room, colour) %>%
    tally() %>% 
    spread(colour, n) %>%
    adorn_totals("col", name = "Count") %>%
    adorn_totals("row",name = "Total")

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top