Mutate 與 count 的綜合應用
你可以把多個動詞串在一起,來回答越來越複雜的資料問題。舉例來說:「哪些美國州份有最多人步行上班?」
你會使用 walk 欄位(每個郡縣中步行上班人口的百分比),據此新增一個欄位,並進行計數。
counties_selected <- counties %>%
select(county, region, state, population, walk)
本練習屬於課程
使用 dplyr 進行資料操作
練習說明
- 使用
mutate()計算並新增名為population_walk的欄位,內容為該郡縣步行上班的總人口數。 - 使用(加權且排序的)
count(),找出各州步行上班的總人口數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
counties_selected %>%
# Add population_walk containing the total number of people who walk to work
___
# Count weighted by the new column, sort in descending order
___