Rei Rosemary
Rei Rosemary

Reputation: 7

How can i remove this data?

I wanna remove part of 'city_' all of them. What kind of function should i use in RStudio?

city data

Upvotes: 0

Views: 33

Answers (3)

Ronak Shah
Ronak Shah

Reputation: 388982

You can use readr::parse_number which would automatically extract numbers from the column.

df$city <- readr::parse_number(df$city)

Upvotes: 0

Chris Ruehlemann
Chris Ruehlemann

Reputation: 21400

You can use a negative character class that removes anything that is not a digit:

df$city <- as.numeric(gsub("\\D", "", df$city))

Upvotes: 1

ThomasIsCoding
ThomasIsCoding

Reputation: 101335

I think you want to use gsub

transform(
  df,
  city = as.numeric(gsub("city_","",city))
)

Upvotes: 1

Related Questions