How to make data into groups and then into subgroups
step1: I wanna group the dataset into [0,0.5Y),[0.5Y,2Y),[2Y,4Y]
step2: make data in each group into smaller subgroups.
step3: see the distribution of each groups and each subgroup
step4: substract the first calue in each smaller subgroup
For step1&2, since it requires to group data twice, and the range of smaller subgroups are not the same, I'm quiet confused about how to make my code in the most efficient way.
For step 3, I think I can create a dataset consisting of major groups and the other one consisting of all the subgroups, and then plot two scatter plots seperately.
dataframe<-df <- data.frame( maturity=c("0.24Y","0.6Y","0.7Y","0.9Y","0.98Y","3Y","3.5Y","2.9Y","0.32Y"), price = c(2,4,3,6,23,4,7,2,7))