bg_11
bg_11

Reputation: 25

How to deal with data frame column headers that have hyphens in them?

I have a data frame that was scraped from a webpage. Some of the column headers have hyphens in them (for example, ERA-), and it does not seem like dplyr allows me to deal with them.

I am trying to do this:

dataframe_new <- dataframe_old %>%
   transmute(ERA_minus = ERA-)

but I keep getting Error: unexpected ')' in:

I'm pretty new to R, so what's the best way to deal with something like this?

Upvotes: 1

Views: 53

Answers (1)

akrun
akrun

Reputation: 887213

We could use backquotes for those columns

library(dplyr)
dataframe_old %>%
   transmute(ERA_minus = `ERA-`)

Upvotes: 1

Related Questions