summarizing counts of a factor with dplyr

前端 未结 3 1348
天涯浪人
天涯浪人 2020-12-24 13:38

I want to group a data frame by a column (owner) and output a new data frame that has counts of each type of a factor at each observation. The real data frame is fairly larg

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 14:10

    If you wanted to forego the dplyr, you can split into lists.

    df <- split(df, list(df[[obs1]], df[[obs2]])
    

    If you wanted the count, you just create an sapply or lapply call to run through the lists and get the count of each one. Or literally any other function you want.

提交回复
热议问题