Variable name in R

Viewed 153

I have a CSV file that I want to analyze in R. One of the variable names is Team/NOC. When I try to filter this variable I get an error message (probably because of the forward slash in the variable name).

  • My code:
filter(Medals,Team/NOC=="Japan")
  • The error message:

Error: Problem with filter() input ..1. i Input ..1 is Team/NOC == "Japan". x object 'Team' not found

So, how can I solve this problem please?

1 Answers

As stated in this answer:

A pair of backticks is a way to refer to names or combinations of symbols that are otherwise reserved or illegal.

You need to protect your attributes doing the following:

filter(Medals, `Team/NOC` == "Japan")
Related