I have a dateset like this:
##current state of data
team= c("a","a","a","a","b","b","b","b")
situation=c("fives","fives","short","short","fives","fives","short","short")
year= c("2014","2015","2014","2015","2014","2015","2014","2015")
shots= runif(8, min = 2, max=10)
saves= runif(8, min = 1, max=6)
df = data.frame(team,year,situation, shots, saves)
I want the dataset to look like this:
team = c("a","b")
fives2014shots = runif(2, min = 2, max=10)
fives2015shots = runif(2, min = 2, max=10)
short2014shots = runif(2, min = 2, max=10)
short2015shots = runif(2, min = 2, max=10)
fives2014saves = runif(2, min = 1, max=6)
fives2015saves = runif(2, min = 1, max=6)
short2014saves = runif(2, min = 1, max=6)
short2015saves = runif(2, min = 1, max=6)
data.frame(team, fives2014shots,fives2015shots,
fives2014saves,fives2015saves, short2014shots, short2015shots,
short2014saves, short2015saves)
This code gives me the closest result but it only shows the 'saves' numeric variable and I need 'saves' and 'shots' to now show as part of the new column names:
library(reshape)
cast(df, team ~ year + situation)
Thank you!