简体   繁体   English

R group_by 和summary 不能正常工作.. 不知道为什么

[英]R group_by and summarize is not working as it should.. no clue why

This should REALLY work but it doesn't and I lose my mind!这应该真的有效,但它没有,我失去了理智!

This is my data这是我的数据

   > head(dataset_2,n=5)
  CUSTOMER_NUMBER OLD_NEW_CLIENT COMPLETION_PRCT CRASH_RISK
1       535961675     Old client            0.06         25
2       223186690     Old client            0.04         24
3       217140964     Old client            0.05         32
4       514559839     Old client            0.10         52
5        10991413     Old client            0.53         15

> str(dataset_2)

'data.frame':   90405 obs. of  4 variables:
 $ CUSTOMER_NUMBER: int  535961675 223186690 217140964 514559839 10991413 506839750 15102896 34980927 578647941 804552857 ...
 $ OLD_NEW_CLIENT : chr  "Old client" "Old client" "Old client" "Old client" ...
 $ COMPLETION_PRCT: num  0.06 0.04 0.05 0.1 0.53 0.05 0.06 0.06 1 0.09 ...
 $ CRASH_RISK     : num  25 24 32 52 15 38 42 42 41 78 ...
 - attr(*, ".internal.selfref")=<externalptr> 

I want to summarise count of clients by all other columns - so combinations of old_new_client, completion_prct and crash_risk and a count of clients falling into this bucket.我想总结所有其他列的客户端数量 - 所以 old_new_client、completion_prct 和 crash_risk 的组合以及落入这个桶的客户端数量。 But when I type code:但是当我输入代码时:

  by_parameters <-dataset_2 %>%
  group_by(OLD_NEW_CLIENT, COMPLETION_PRCT, CRASH_RISK) %>%
  summarize(clients=n_distinct(CUSTOMER_NUMBER))

I get:我得到:

> by_parameters
  clients
1   90399

Thanks for any help!谢谢你的帮助!

OK!好的! Using dyplyr I/o plyr helped!使用 dyplyr I/o plyr 有帮助! solved解决了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM