concept mutate() in category R

appears as: mutate()
Exploring Data with R

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

  • mutate() — Create new variables with functions of existing variables
  • It turns out that the mutate() function is very powerful. We can have multiple mutations in a single call of mutate(). What’s even more interesting (and useful) is that a variable created in an expression is immediately available for use in a following expression (Listing 2.22).

    Listing 2.22 Add the `bmi` column as before and then create `bmi_rnd`.
    ```{r mutate_bmi_round, paged.print=FALSE}
    mutate( //#A
      sw_small, //#B
      bmi = mass / (height / 100)^2, //#C
      bmi_rnd = round(bmi, 0) //#D
    )

    Here is the output from this single, two-expression mutate() call: