It is easy to calculate the mean of each group in an R dataframe. If you want to exclude the current observation, it is almost as easy.
Is there any easy way to exclude the current observation when calculating the standard deviation?
For example, when I have this table
data.frame(country = c(rep("A",3), rep("B",3)), weight = c(10,11,12,20,25,30))
, I need the following table:
data.frame(country = c(rep("A",3), rep("B",3)), weight = c(10,11,12,20,25,30), standarddeviation = c(sd(c(11,12)), sd(c(10,12)), sd(c(10,11)), sd(c(25,30)), sd(c(20,30)), sd(c(20,25))))