Skip to content
Prev 273048 / 398506 Next

Help with cast/reshape

I realize that this is terribly basic, but I just don't seem to see it at this moment, so I would very much appreciate your help.


How shall I transform this dataframe:
? Name Index Value
1??? a???? 1?? 0.1
2??? a???? 2?? 0.2
3??? a???? 3?? 0.3
4??? a???? 4?? 0.4
5??? b???? 1?? 2.1
6??? b???? 2?? 2.2
7??? b???? 3?? 2.3
8??? b???? 4?? 2.4


into this dataframe:
??? Index? a?? ??? b
1? 1 ??? 0.1 ??? 2.1
2? 2 ??? 0.2 ??? 2.2
3? 3 ??? 0.3 ??? 2.3
4? 4 ??? 0.4 ??? 2.4


df1 = data.frame(c("a", "a", "a", "a", "b", "b", "b", "b"), c(1,2,3,4,1,2,3,4), c(0.1, 0.2, 0.3, 0.4, 2.1, 2.2, 2.3, 2.4))
colnames(df1) = c("Name", "Index", "Value")

df2 = data.frame(c(1,2,3,4), c(0.1, 0.2, 0.3, 0.4), c(2.1, 2.2, 2.3, 2.4))
colnames(df2) = c("Index", "a", "b")


Thank you very much.

Dana