Creating a table() of counts using a frequency column

后端 未结 2 1978
悲&欢浪女
悲&欢浪女 2021-01-22 12:20

I\'ve got data created from the HairEyeColor data

HEC = as.data.frame(HairEyeColor)

which is

2条回答
  •  不知归路
    2021-01-22 12:41

    We do a group by summarise and then spread

    library(tidyerse)
    HEC %>% 
        group_by(Hair, Eye) %>% 
        summarise(Freq = sum(Freq)) %>%
        spread(Eye, Freq)
    

    It can be also done in a one-liner

    xtabs(Freq ~ Eye + Hair, HEC)
    

提交回复
热议问题