Archit Chawla
Archit Chawla

Reputation: 67

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

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"

Upvotes: 0

Views: 841

Answers (1)

skyCode
skyCode

Reputation: 386

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)

Upvotes: 2

Related Questions