Remember y'all, if you want to `dplyr::summarise` after testing a condition, do `dplyr::filter` first, not try and put the logic in the summarize command itself, where you will end up summarizing on a logical vector instead of the data itself.
Remember y'all, if you want to `dplyr::summarise` after testing a condition, do `dplyr::filter` first, not try and put the logic in the summarize command itself, where you will end up summarizing on a logical vector instead of the data itself.
@job_n My motivating example was the plot below:
There are a **lot** of values with 0 standard deviation in this plot (solid lines at left). I want to get summaries of these distributions, both with and without the zeros included.
```
data |>
summarize(mean_all = mean(sd), mean_no0 = mean(sd > 0))
```
Was what I first tried.
But really, I wanted:
```
all_summary = data |>
summarize(mean_all = mean(sd))
no0_summary = data |>
filter(sd > 0) |>
summarize(mean_no0 = mean(sd))
```