I am dealing a problem that assigns serval numbers in a column to be its corresponding characterized intervals. The intervals and its original values examples are shown below
VehicleDriverCarrierPremium_Interval<-c("(Null)",">= 0, <100",">= 100, < 200",">= 200, < 300",">= 300, < 400",">= 400, < 500",">= 500, < 600",">= 600, < 700",">= 700, < 800",">= 800, < 900")
VehicleDriverCarrierPremium<-c(423,12,NA,535,231,875)
What I want at the end would be like this:
VehicleDriverCarrierPremium [1] ">= 400, < 500" ">= 0, <100" "(Null)" ">= 500, < 600" ">= 200, < 300" ">= 800, < 900"
The problems are the original values is from 0 to 50000, and the interval levels actually do not have certain patterns, the length of the intervals will be changed as the value get larger. And there is a comma if the value is great than 1000. For example, the last two intervals are:
">= 9,000, <10,000", ">= 10,000, <50,000"
What I have done so far is very manual, I divide the different intervals into several groups and use the if and for statement to convert the original values to be its corresponding intervals. But when the levels of intervals and length of intervals changed, I have to changed manually.
So I am wondering if there is any better way can read the levels of intervals first, whose type is character. And then change the original values that falls into its corresponding intervals to be its interval.
Please let me know if you have any more information. Thank you!