I have a really messy data set and the following data frame represents a part of it
Causenum<-c("TIMOTHY JAMES", "Disp Type/Case ID","DTCGL","CR01785",
"CR02099","DTCNG","CR01061","CR01329")
case<-c(NA,"Description","Tried by Court - Guilty","ST V WILLIAMS","ST V YOUNG III","Tried by Court -
Not Guilty",
"ST V HARRISON","ST V GOMEZ")
data.frame(Causenum,case)
Causenum case
1 TIMOTHY JAMES <NA>
2 Disp Type/Case ID Description
3 DTCGL Tried by Court - Guilty
4 CR01785 ST V WILLIAMS
5 CR02099 ST V YOUNG III
6 DTCNG Tried by Court - Not Guilty
7 CR01061 ST V HARRISON
8 CR01329 ST V GOMEZ
The two columns contain a lot of information that should be there. Basically I want to make sure that all the rows below DTCGL are grouped by DTCGL and the same for DTCNG
so that It looks as follows
Causenum case newcol
CR01785 ST V WILLIAMS DTCGL
CR02099 ST V YOUNG III DTCGL
CR01061 ST V HARRISON DTCNG
CR01329 ST V GOMEZ DTCNG
how do I do this?