Reputation: 79
I have a column within a dataframe which has numbers followed with decimals which I want to remove to make it more tidy and sortable. How would i remove these numeric decimals?
a<-c("12. one", "1. blah", "189. hi")
b<-c(a,b,c)
df<-data.frame(a,b)
I want to remove the numbers and decimals that begin each variable in column a of this dataframe
Upvotes: 0
Views: 238
Reputation: 887291
We can use sub
to match one or more digits followed by a digit and any spaces from the start (^
) of the string, replace with blank (""
)
sub("^\\d+\\.\\s*", "", a)
#[1] "one" "blah" "hi"
Or if the order of dots, numbers are different, then use the pattern to match 0 or more digits, dot followed by any space, replace with blank (""
)
sub("^[0-9.]*\\s?", "", a)
Upvotes: 1