始める無料で始める

4つの動詞から適切なものを選ぶ

この章では、4つの動詞 select()mutate()relocate()rename() を学びました。ここでは、各状況に合った動詞を選びます。かっこの中身を変更する必要はありません。

この演習はコースの一部です

dplyr で行うデータ操作

コースを見る

演習の手順

  • unemployment 列名を unemployment_rate に変更するのに適切な動詞を選んでください。
  • statecounty、および poverty を含む列だけを残すのに適切な動詞を選んでください。
  • 女性で構成される人口の割合を表す新しい列 fraction_women を、どの列も落とさずに計算してください。
  • statecounty、そして employed / populationemployment_rate と名付けた列の3列だけを残してください。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# 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)
コードを編集して実行