Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference a dataframe column that is named with a reserved word

Tags:

dataframe

r

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

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

like image 457
Parseltongue Avatar asked Mar 30 '16 15:03

Parseltongue


1 Answers

Use this syntax to select column "repeat":

data$`repeat`
like image 146
gwatson Avatar answered Oct 04 '22 20:10

gwatson