I want to add a column in r to calculate the difference of scores for every equal characters in the same column (e.g:names)
I tried to group the data using group_by function in dplyr but it didn't work. 
I want to add a column in r to calculate the difference of scores for every equal characters in the same column (e.g:names)
I tried to group the data using group_by function in dplyr but it didn't work. 
 
    
     
    
    Something like this?
library(dplyr)
df %>% group_by(name) %>% mutate(score_diff = c(0, diff(score)))
## A tibble: 6 x 3
## Groups:   name [4]
#  name      score score_diff
#  <fct>     <dbl>      <dbl>
#1 James        83          0
#2 Andrew       84          0
#3 James        87          4
#4 Sonya        40          0
#5 Catherine    50          0
#6 Sonya        55         15
df <- data.frame(
    name = c("James", "Andrew", "James", "Sonya", "Catherine", "Sonya"),
    score = c(83,84,87,40,50,55))
