If you want the mean, you could use dplyr syntax:
df = structure(list(ID = c(101L, 101L, 101L, 102L, 102L, 102L, 103L,103L, 103L),
rating = c(60L, 78L, NA, 60L, NA, 75L, NA, 68L, 70L),
Sur = c(0.7687, NA, 0.765, NA, 0.654, 0.435, 0.576, 0.875, NA)),
.Names = c("ID", "rating", "Sur"), class = "data.frame", row.names = c(NA,-9L))
library(dplyr)
df %>%
group_by(ID) %>%
mutate(rating = ifelse(is.na(rating), mean(rating, na.rm = TRUE), rating),
Sur = ifelse(is.na(Sur), mean(Sur, na.rm = TRUE), Sur))
ID rating Sur
<int> <dbl> <dbl>
1 101 60.0 0.76870
2 101 78.0 0.76685
3 101 69.0 0.76500
4 102 60.0 0.54450
5 102 67.5 0.65400
6 102 75.0 0.43500
7 103 69.0 0.57600
8 103 68.0 0.87500
9 103 70.0 0.72550
for other imputations you can look at packages like mi, mice, caret, amelia or simputation. And I'm probably forgetting a lot of others. Personally I like the simplicity of simputation.
For example median imputation is just one line:
impute_median(df, rating + Sur ~ ID)