Home > database >  How do I remove the dollar sign with str_replace in a dataframe variable in R?
How do I remove the dollar sign with str_replace in a dataframe variable in R?

Time:09-10

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"

CodePudding user response:

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)
  • Related