開始使用免費開始

清理字串

在這一課中,你學到一些「regex」(規則表示式)的基礎,用來擷取一般性的樣式。我們介紹了兩種符號:

Expression Does this
. 比對任一字元
* 出現 0 次或多次

例如,「.*science 」會在字串「data science rocks!」中比對到「data science 」。

接下來,就用你所學來修改你在前一課建立的資料集 gathered_data 裡的 response_var

本練習屬於課程

Tidyverse 的類別資料

檢視課程

練習說明

  • 使用 str_remove,將 response_var 欄位中「rude to 」這段(包含最後的空格)以及其之前的所有內容一併移除。
  • 再使用 str_remove,把 response_var 欄位中的「on a plane」移除。

動手互動練習

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

gathered_data %>%
    # Remove everything before and including "rude to " (with that space at the end!)
    mutate(response_var = ___(response_var, ___)) %>%
    # Remove "on a plane"
    mutate(response_var = ___(response_var, ___))
編輯並執行程式碼