4つの動詞から適切なものを選ぶ
この章では、4つの動詞 select()、mutate()、relocate()、rename() を学びました。ここでは、各状況に合った動詞を選びます。かっこの中身を変更する必要はありません。
この演習はコースの一部です
dplyr で行うデータ操作
演習の手順
unemployment列名をunemployment_rateに変更するのに適切な動詞を選んでください。state、county、およびpovertyを含む列だけを残すのに適切な動詞を選んでください。- 女性で構成される人口の割合を表す新しい列
fraction_womenを、どの列も落とさずに計算してください。 state、county、そしてemployed / populationをemployment_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)