concept avg_mass in category R

appears as: vg_mass
Exploring Data with R

This is an excerpt from Manning's book Exploring Data with R.

Notice that we get two columns back: one is from the species group and one is from the column we defined in the summarize() statement (avg_mass).

#> # A tibble: 38 x 2
#>    species   avg_mass
#>    <chr>        <dbl>
#>  1 Aleena          15
#>  2 Besalisk       102
#>  3 Cerean          82
#>  4 Chagrian        NA
#>  5 Clawdite        55
#>  6 Droid           NA
#>  7 Dug             40
#>  8 Ewok            20
#>  9 Geonosian       80
#> 10 Gungan          NA
#> # … with 28 more rows

The pattern will hold that we get all grouping columns and all summary columns back. Another observation here is that some values for avg_mass appear as NA. This occurs if any NA values are introduced to mean(), the result will invariably be NA (the behavior holds true for the other aggregation functions as well). To circumvent this, we can exclude NA values in the calculation of the mean by using the na.rm = TRUE option within mean(). Let’s now revise that summarize() statement (Listing 2.24).

Listing 2.24 A slight modification to the summary expression to deal with missing (NA) values.
```{r summarize_mean_na_rm, paged.print=FALSE}
summarize(by_species, avg_mass = mean(mass, na.rm = TRUE)) //#A
```

Now we see that all values in the avg_mass column are non-NA, however, there is now at least one NaN (not a number) value: