开始使用免费开始使用

清理字符串

在本课中,您学习了正则表达式(简称 "regex")的一些基础,它可以用来捕捉通用模式。我们介绍了两种记号:

Expression Does this
. 匹配任意单个字符
* 重复零次或多次

例如,".*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, ___))
编辑并运行代码