Vote count:
0
I have a data.frame:
vector <- data.frame(patient=rep(1:5,each=2),medicine=rep(1:3,length.out=10),prob=rnorm(10))
I want to get the mean of the "prob" column while grouping by patient. I do this with the following code:
vector %>%
group_by(patient) %>%
summarise(average=mean(prob))
This code perfectly works. However, I need to get the same values without using the word "prob" on the "summarise" line. I tried the following code, but it gives me a data.frame in which the column "average" is a vector with 5 identical values, which is not what I want:
vector %>%
group_by(patient) %>%
summarise(average=mean(vector[,3]))
asked 48 secs ago
Error dplyr summarise
Aucun commentaire:
Enregistrer un commentaire