I have two columns in my data as shown below. I want to insert rows based on the value in Total column. Eg. For record1, the total value is 9. So, there should be 9 records for
First make that data frame you expect beforehand, after that make your desired data frame:
dat <- data.frame("Code"=c("XS1.1","W1.23","Kj1.9"),"Total"=c(9,3,2)) dat2 <- data.frame("Code"=rep(dat[,1],dat[,2]),"Total"=c(seq(1:dat[1,2]),seq(1:dat[2,2]),seq(1:dat[3,2])))