Reputation: 7
I wanna remove part of 'city_' all of them. What kind of function should i use in RStudio?
Upvotes: 0
Views: 33
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
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
Reputation: 101335
I think you want to use gsub
transform(
df,
city = as.numeric(gsub("city_","",city))
)
Upvotes: 1