0

I have a dataframe in R with one variable called FARE that has a dollar sign. I need to remove the dollar sign in it. How do I remove it?

airline.df$FARE[1] --> returns "$84.23"
  • `sub("^\\$", "", airline.df$FARE)` – r2evans Sep 09 '22 at 23:43
  • I suggest looking at https://stackoverflow.com/a/22944075/3358272 for a brief regex discussion, and https://regexr.com/, https://regex101.com/ for more details and workable examples. – r2evans Sep 09 '22 at 23:44
  • or if you really need to use `stringr`, then `str_replace(airline.df$FARE, "\\$", "")` – r2evans Sep 09 '22 at 23:45

1 Answers1

1

You can use the approach of replacing it with an empty char:

str_replace(airline.df$FARE[1], "\\$", "");

Or you can remove the first char ($) by creating the substring that starts with second character.

fare = substring(airline.df$FARE[1], 2)
skyCode
  • 358
  • 1
  • 7