0

I am very new to R and have started to learn the basics but I am struggling with the more advance concepts.

For this particular project I am importing game by game stats for basketball via .csv file. Essentially I am trying to figure out the standard deviation of pts scored for each unique player within the data set.

I started down the route of importing the .csv file as "NBA".

Then I used a formula to store each player as a unique variable but that is cumbersome and will exclude when new players play when coming off of injury.

For example I was doing this:

AD= NBA[which(NBA$Name =="Anthony Davis"),]
sd(AD$POINTS)
  • 3
    Some possibilities are [here](https://stackoverflow.com/questions/9723208/aggregate-summarize-multiple-variables-per-group-e-g-sum-mean). – Nick Criswell Dec 10 '18 at 13:46
  • 3
    I really dislike that duplicate as the data format of the dupe requires reshaping, making it harder for new users to generalize to use cases that don't need reshaping. The accepted answer there is to first `melt` and then `dcast`, which isn't a good solution here. I'd much prefer to mark as a duplicate of the R-FAQs [How to sum a variable by group?](https://stackoverflow.com/q/1660124/903061) or [Calculate the mean by group](https://stackoverflow.com/q/11562656/903061) with the advice to just replace `sum` or `mean` with `sd`. (Which is what I'm going to do.) – Gregor Thomas Dec 10 '18 at 14:06

1 Answers1

3

This should do what you want:

require(dplyr)
NBA %>% 
  group_by(Name) %>% 
  summarise(sd = sd(POINTS))
JayJay81
  • 203
  • 1
  • 8