I want to calculate the mean given a certain condition is met.
And have the code below.
How do you rewrite this to get R to do the mean for df$sta== B, C, etc. in one go and provide printed output in the Rstudio console.

```
 id<-c(1,2,3)
 val<-c(10,15,20)
 sta<-c("A","B","A")

 df<-data.frame(id,val,sta)

 mean(df$val[df$sta=="A"])

```