Hi all,
This is kinda similar to the question I had last week, but I think its a little more complicated.
Basically I have two variables, and I want to perform actions in relation to unique combinations of these variables.
DATE TIME PLAYER SCORE
2012/8/1 Evening BOB 2
2012/8/1 Evening TOM 3
2012/8/1 Evening BOB 1
2012/8/1 Evening BOB 2
2012/8/1 Night BOB 1
2012/8/1 Night BOB 1
2012/8/2 Evening TOM 1
2012/8/2 Evening TOM 3
My goal is summarize this data based on the two factors, DATE and TIME.
I want to count the unique players for each unique factor combination, and also have the average value for the scores. I tried using tapply and rle but with no luck. Here is what the desired result would look like;
DATE TIME UNIQUE PLAYERS AVERAGE SCORE
2012/8/1 Evening 2 2
2012/8/1 Night 1 1
2012/8/2 Evening 1 2
I've been at it for over 5 hours and I'm not much closer to a solution than when I started. Any help would be greatly appreciated, thank you.
"Code for Example"
This is kinda similar to the question I had last week, but I think its a little more complicated.
Basically I have two variables, and I want to perform actions in relation to unique combinations of these variables.
DATE TIME PLAYER SCORE
2012/8/1 Evening BOB 2
2012/8/1 Evening TOM 3
2012/8/1 Evening BOB 1
2012/8/1 Evening BOB 2
2012/8/1 Night BOB 1
2012/8/1 Night BOB 1
2012/8/2 Evening TOM 1
2012/8/2 Evening TOM 3
My goal is summarize this data based on the two factors, DATE and TIME.
I want to count the unique players for each unique factor combination, and also have the average value for the scores. I tried using tapply and rle but with no luck. Here is what the desired result would look like;
DATE TIME UNIQUE PLAYERS AVERAGE SCORE
2012/8/1 Evening 2 2
2012/8/1 Night 1 1
2012/8/2 Evening 1 2
I've been at it for over 5 hours and I'm not much closer to a solution than when I started. Any help would be greatly appreciated, thank you.
"Code for Example"
Code:
DATE=c(rep("2012/8/1",6),rep("2012/8/2",2))
TIME=c(rep("Evening",4),rep("Night",2),rep("Evening",2))
PLAYER=c("BOB","TOM",rep("BOB",4),rep("TOM",2))
SCORE=c(2,3,1,2,1,1,1,3)
dat=data.frame(DATE,TIME,PLAYER,SCORE)