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

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

问题描述

 主题Cat Nbr标题说明...模式! 
1 XYZ 101简介我在线
2 XYZ 102简介II CAMPUS
3 XYZ 135高级CAMPUS

我想使用 dplyr :: rename()



<$ p重命名列$ p> df%>%
重命名(subject = Subject,
code = Cat Nbr,
title = title,
mode =模式!)

但是我收到一个错误:意外符号: / code>



如何调和?

解决方案

p>要引用包含非标准字符或以数字开头的变量,请将名称换成后面的勾号,例如`Instruction..Mode!`


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

I would like to rename the columns with dplyr::rename()

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

But I am getting an Error: unexpected symbol in:

How might I reconcile this?

解决方案

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天全站免登陆