I want to switch from long to wide format. My data is as follows:
day=c(1,2,3,4,5,6,1,2,3,4,5,6)
site=c('a', 'a', 'a', 'a', 'a', 'a', 'b', 'b', 'b', 'b', 'b', 'b')
value.1=c(1,2,5,7,5,3,9,4,2,8,1,8)
value.2=c(5,4,7,6,2,4,6,9,4,2,5,6)
data=data.frame(day,site,value.1,value.2)
> data
day site value.1 value.2
1 1 a 1 5
2 2 a 2 4
3 3 a 5 7
4 4 a 7 6
5 5 a 5 2
6 6 a 3 4
7 1 b 9 6
8 2 b 4 9
9 3 b 2 4
10 4 b 8 2
11 5 b 1 5
12 6 b 8 6
I want to switch it to a wide format based on the site. So it looks like
> data
day a.value.1 a.value.2 b.value.1 b.value.2
1 1 1 5 9 6
2 2 2 4 4 9
3 3 5 7 2 4
4 4 7 6 8 2
5 5 5 2 1 5
6 6 3 4 8 6
It seems to me that I can do this with the package reshape, but I can not understand it
I would like to help with this. Thanks you