开始使用免费开始使用

在四个动词中做选择

本章中,您学习了四个动词:select()mutate()relocate()rename()。在这里,您将为每种情形选择合适的动词。您不需要修改圆括号内的任何内容。

本练习是课程的一部分

使用 dplyr 进行数据处理

查看课程

练习说明

  • 选择合适的动词,将 unemployment 列名改为 unemployment_rate
  • 选择合适的动词,仅保留 statecounty 以及所有包含 poverty 的列。
  • 计算一个名为 fraction_women 的新列,表示女性占总人口的比例,且不删除任何列。
  • 仅保留 3 列:statecounty,以及 employed / population,并将其命名为 employment_rate

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Change the name of the unemployment column
counties %>%
  ___(unemployment_rate = unemployment)

# Keep the state and county columns, and the columns containing poverty
counties %>%
  ___(state, county, contains("poverty"))

# Calculate the fraction_women column without dropping the other columns
counties %>%
  ___(fraction_women = women / population)

# Move the region column to before state
counties %>%
  ___(region, .before = state)
编辑并运行代码