I ran into some problem when trying to use the statar::xtile function together with dplyr.
I have a dataset called "resp_rate" as follows:
userid group_id group_resp_rate 63775658 514 0.0315789 64880613 514 0.0315789 65051746 553 0.0035461 66689882 554 0.0000000 68839217 555 0.0038023 70630920 555 0.0038023 73773882 554 0.0000000 74279814 524 0.0000000 74461297 555 0.0038023 74951919 553 0.0035461 75523813 514 0.0315789 75932923 554 0.0000000 76678559 554 0.0000000 77506998 554 0.0000000 79261032 514 0.0315789 79860954 555 0.0038023 80016586 554 0.0000000 81757979 515 0.0106383 82565883 534 0.0000000 82610815 513 0.0212766
I need to divide customers into 3 groups based on group_resp_rate. The groups do not have to be equal-sized.
When using xtile from statar directly, it works out. E.g.:
resp_rate$group_index1 <- xtile(resp_rate$group_resp_rate, n=3)
However, when I use xtile with dplyr, it results in only one level index:
resp_prob <- resp_prob %>% mutate(group_index2 = xtile(group_resp_rate, n=3))
This is the resulted dataset:
userid group_id group_resp_rate group_index1 group_index2 63775658 514 0.0315789 3 1 64880613 514 0.0315789 3 1 65051746 553 0.0035461 2 1 66689882 554 0.0000000 1 1 68839217 555 0.0038023 2 1 70630920 555 0.0038023 2 1 73773882 554 0.0000000 1 1 74279814 524 0.0000000 1 1 74461297 555 0.0038023 2 1 74951919 553 0.0035461 2 1 75523813 514 0.0315789 3 1 75932923 554 0.0000000 1 1 76678559 554 0.0000000 1 1 77506998 554 0.0000000 1 1 79261032 514 0.0315789 3 1 79860954 555 0.0038023 2 1 80016586 554 0.0000000 1 1 81757979 515 0.0106383 3 1 82565883 534 0.0000000 1 1 82610815 513 0.0212766 3 1
Can someone let me know why this is happening? Really appreciate it!