引用以保留字命名的数据框列 [英] Reference a dataframe column that is named with a reserved word

查看:46
本文介绍了引用以保留字命名的数据框列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚导入了列名之一为 repeat的数据。如果我尝试通过 data $ repeat 引用该列,则会收到错误 Error: data $ repeat中意外的 repeat。当我在线性回归中引用 repeat 时,也会发生相同的问题。

I have just imported data where one of the column names is "repeat." If I try to reference the column via data$repeat, I get an error Error: unexpected 'repeat' in "data$repeat". The same problem happens when I reference repeat inside of a linear regression.

如何更改带有保留字的列以更改列或在线性回归中使用它?

How can I reference a column with a reserved word in order to either change the column or use it in a linear regression?

data <- data.frame('repeat' = 1, 'break' = 2, check.names = FALSE)
data

#   repeat break
# 1      1     2

data$repeat




错误: data $ repeat中意外的重复

Error: unexpected 'repeat' in "data$repeat"


推荐答案

使用此语法选择列重复

data$`repeat`

这篇关于引用以保留字命名的数据框列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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