处理空格和“怪异"dplyr::rename() 列名中的字符 [英] Dealing with spaces and "weird" characters in column names with dplyr::rename()

查看:20
本文介绍了处理空格和“怪异"dplyr::rename() 列名中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格有这样困难的标题:

I have table with difficult headers like this:

  Subject  Cat Nbr  Title       Instruction..Mode!
1 XYZ      101      Intro I     ONLINE
2 XYZ      102      Intro II    CAMPUS
3 XYZ      135      Advanced    CAMPUS

我想用 dplyr::rename()

df %>%
 rename(subject = Subject, 
        code = Cat Nbr, 
        title = title, 
        mode = Instruction..Mode!)

但我收到一个 Error: unexpected symbol in:

我该如何协调?

推荐答案

要引用包含非标准字符或以数字开头的变量,请将名称用反引号括起来,例如,`Instruction..Mode!`

To refer to variables that contain non-standard characters or start with a number, wrap the name in back ticks, e.g., `Instruction..Mode!`

这篇关于处理空格和“怪异"dplyr::rename() 列名中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆