0

I have a big data set that in its short version looks like this:

Subject RTs     Block       Reward    Congruency
sub02   409.1   inform      nonrew    con
sub02   522.8   inform      rew       incon
sub02   512.6   noninform   nonrew    incon
sub02   425.5   noninform   rew       con
sub03   409.1   inform      nonrew    con
sub03   522.8   inform      rew       incon
sub03   512.6   noninform   nonrew    incon
sub03   425.5   noninform   rew       con

I am trying to calculate quantiles per subject using this function but checking the data afterwwards it seems that the fucntion doesn't compute the quantiles per subject:

hits <- hits %>% group_by(Subject) %>% 
  mutate(quan = ntile(RTs, 4)) %>% 
  as.data.frame()

Is there any alternative way of doing the same thing? Ot maybe something is wrong with my code?..

MariKo
  • 305
  • 4
  • 15
  • Output looks ok for me, can you explain why it "seems that the fucntion doesn't compute the quantiles per subject"? You can also try to replace `ntile` with `order()`. – pogibas Apr 13 '18 at 14:22
  • if you want to calculate the quantiles why you don't use `quantile()` – Andre Elrico Apr 13 '18 at 14:24
  • 1
    The most common reason for `dplyr::group_by` to not work is if you loaded `plyr` after `dplyr` and are accidentally using `plyr::mutate` instead of `dplyr::mutate`. [See this FAQ](https://stackoverflow.com/q/26106146/903061) – Gregor Thomas Apr 13 '18 at 14:38
  • @PoGibas, when I subset four datasets per each quartile, the number of rows is different because for one or two participant the 4th quartile doesn't exist. So, then I assume that the `group_by(Subject)` didn't work properly. – MariKo Apr 23 '18 at 09:43
  • @Gregor, indeed, the order of the plyr and dplyr packages was the problem, thank you! – MariKo May 02 '18 at 14:59

0 Answers0