開始使用免費開始

分組並重塑相似欄位

在本課中,你看到 Kaggle 資料科學問卷資料集中的一些欄位彼此相關,例如各種工作挑戰出現頻率的欄位。我們通常會想把這些變數放在一起看,但首先要先把它們找出來,並轉換成更好用的格式。現在就以受訪者覺得不同學習平台有多實用的相關題目,來練習這個流程。

資料集 multiple_choice_responses 已為你載入。

本練習屬於課程

Tidyverse 的類別資料

檢視課程

練習說明

  • 僅選取欄名中包含 "LearningPlatformUsefulness" 的欄位。
  • 將資料從寬格式轉為長格式,並建立兩個欄位:learning_platformusefulness
  • 移除 usefulness 為 NA 的列。
  • learning_platform 的每個字串中移除 "LearningPlatformUsefulness"

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

learning_platform_usefulness <- multiple_choice_responses %>%
  # Select columns with LearningPlatformUsefulness in title
  ___(___("LearningPlatformUsefulness")) %>%
  # Change data from wide to long
  ___(everything(), names_to = "learning_platform", values_to = "usefulness") %>%
  # Remove rows where usefulness is NA
  ___(___()) %>%
  # Remove "LearningPlatformUsefulness" from each string in learning_platform 
  mutate(learning_platform = ___())
編輯並執行程式碼