You can do the transformation using dplyr
and reshape2
:
df <- data.frame(name=c("name.a",
"name.a",
"name.a",
"name.b",
"name.b",
"name.b",
"name.c",
"name.c",
"name.c"),
num=c(5,
4,
1,
2,
3,
2,
1,
5,
6))
df <- df %>%
group_by(name) %>%
mutate(instance = 1:n())
dcast(df,name~instance,sum,value.var='num')