x
Team Date Score A 1-1-2012 80 A 1-2-2012 90 A 1-3-2012 50 A 1-4-2012 40 B 1-1-2012 100 B 1-2-2012 60 B 1-3-2012 30 B 1-4-2012 70 etc
I need and can turn this data frame into a wide data frame, one row for each command with all the observations and dates as a header:
xx
Team 1-1-2012 1-2-2012 1-3-2012 1-4-2012 A 80 90 50 40 B 100 60 30 70
I need to calculate the average and sd for each row, what can I do:
xx
Team 1-1-2012 1-2-2012 1-3-2012 1-4-2012 mean sd A 80 90 50 40 75 20 B 100 60 30 70 55 10
Given that I have thousands of rows in an xx data frame. I would like to do the calculations for each cell as follows:
if abs (xx-Mean)> 3 * SD, create the counter column name and increase the value. The idea is to compare each observation with the average and sd, if each observation for this command corresponds to this - abs (xx-Mean)> 3 * SD, increase the counter. After checking each cell, I would like to look at each counter for each team and get the top ten teams that have the highest counter value. I mainly try to detect the biggest outliers. As soon as I get the top 10 command names, I would like to graphically display their time series data on the data frame x.
Hopefully I wonβt make it more complicated than it should be. Not sure if R already has a function to perform calculations on each cell. Any ideas how to do this are appreciated?
source share