Hello I have a time series dataframe comprised of a list of products and their different tax rates that I need to segregate into two categories: percentages numbers(AV) and text(everything else without percentage numbers (SPEC), that are separated by the first plus sign in the character vector:
#note there are many more years
product <- c("01","02")
yr1<-c("0%","11.5% + 190 GBP/100kg")
yr2<-c("0%","15% + 190 GBP/100kg + MAX 8.5%/100kg")
yearnum =2
sched <- data.frame(product,yr1,yr2)
#where yearnum is the number of years
schedule<-c(paste0("yr",1:yearnum))
#categorize av and specific DUTY rates
for(j in 1:yearnum){
for(i in schedule){
sched <- sched %>% separate(i, c(paste0("av.yr",j), paste0("spec.yr",j)), " \\+ ", remove=F, extra = "merge")}}
I'm trying to separate them into the result below, but there is something wrong with my for loop formulation. Could anyone please help?
#and the output should be
product <- c("01","02")
yr1<-c("0%","11.5% + 190 GBP/100kg")
yr2<-c("0%","15% + 190 GBP/100kg + MAX 8.5%/100kg")
av.yr1<- c("0%","11.5%")
av.yr2 <-c("0%","15%")
spec.yr1 <-c("","190 GBP/100kg")
spec.yr2 <-c("","190 GBP/100kg + MAX 8.5%/100kg")
sched<-data.frame(product,yr1,yr2,av.yr1,av.yr2,spec.yr1,spec.yr2)