Name of the column contains ''in''

Dear all,

For my research I need to create a new subset by removing some columns from the data. I am using the following code:

data_AngNative_raw <- subset(data_AngNative_raw, select = c(-Q1,-EndDate, -Status, -IPAddress, -Progress, -Duration (in seconds), -RecordedDate, -ResponseId))
The problem is that R does not recognise the column Duration (in seconds). I believe, the problem is in the word ''in''. It apparently reads in as a command. What can I do to resolve the issue?

Thank you very much in advance.

The word in is used to specify for loops in R (e.g., for (i in 1:10)), but the underlying issue here is that legal column names in R can't have spaces or parentheses. To let R know that this is a single column, enclose it in backticks (the key in the upper left corner of a U.S. keyboard):

-`Duration (in seconds)`
2 Likes

It would be best if as a general rule you shared the code that triggered the error message as well as the error message itself...

But as a practical approach I recommend you use the janitor package to clean_names before you start working on a dataframe with awkwardy named variables.

https://cran.r-project.org/web/packages/janitor/vignettes/janitor.html#cleaning

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

Thank you very much for your advice, unfortunately, still does not work. I receive the same error:
Error in eval(substitute(select), nl, parent.frame()) :
object 'Duration (in seconds)' not found

Thank you once again.