Session Ready
Exercise

Exercise 8. Arrange

Now we are going to explore differences in systolic blood pressure across races, as reported in the Race1 variable.

We will learn to use the arrange function to order the outcome acording to one variable.

Note that this function can be used to order any table by a given outcome. Here is an example that arranges by systolic blood pressure.

NHANES %>% arrange(BPSysAve)

If we want it in descending order we can use the desc function like this:

NHANES %>% arrange(desc(BPSysAve))

In this example, we will compare systolic blood pressure across values of the Race1 variable for males between the ages of 40-49.

Instructions
100 XP
  • Compute the average and standard deviation for each value of Race1 for males in the age decade 40-49.
  • Order the resulting table from lowest to highest average systolic blood pressure.
  • Use the functions filter, group_by, summarize, arrange, and the pipe %>% to do this in one line of code.
  • Within summarize, save the average and standard deviation of systolic blood pressure as average and standard_deviation.