I am having trouble grouping cancer sites by site code. The data comes with three columns, site_code, site_description, and tot_count. I would like to group the site codes so that it combines the total amounts and lists them as such:
1-10 Oral Cancer
1-10, 34, 35 Head & Neck Cancer
14-24 Colorectal Cancer
60 & 61 Brain Cancer
64 & 65 Hodgkins Lymphoma
66 & 67 Non-hodgkins Lymphoma
69-77 Leukemia
all other unspecified codes would not need to be grouped but their tot counts are still important for analysis.
Please notice that for Oral Cancer and Head & Neck Cancer share overlap of codes. Is it possible to have the tot count count twice? Once in Oral Cancer and again in Head & Neck Cancer?
random_reprex <- data.frame(
stringsAsFactors = FALSE,
site_code = c(1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,21,22,23,24,
25,26,27,28,29,30,31,32,33,34,35,60,61,64,65,
66,67,68,69,70,71,72,73,74,75,76,77),
site_description = c("Lip","Tongue",
"Salivary Gland","Floor of Mouth","Gum and Other Mouth",
"Nasopharynx","Tonsil","Oropharynx","Hypopharynx",
"Other Oral Cavity and Pharynx","Esophagus","Stomach",
"Small Intestine","Cecum","Appendix","Ascending Colon",
"Hepatic Flexure","Transverse Colon","Splenic Flexure",
"Descending Colon","Sigmoid Colon","Large Intestine, NOS",
"Rectosigmoid Junction","Rectum",
"Anus, Anal Canal and Anorectum","Liver","Intrahepatic Bile Duct","Gallbladder",
"Other Biliary","Pancreas","Retroperitoneum",
"Peritoneum, Omentum and Mesentery","Other Digestive Organs",
"Nose, Nasal Cavity and Middle Ear","Larynx","Brain",
"Cranial Nerves Other Nervous System","Hodgkin - Nodal",
"Hodgkin - Extranodal","Non-Hodgkin Lymphoma - Nodal",
"Non-Hodgkin Lymphoma - Extranodal","Myeloma",
"Acute Lymphocytic Leukemia","Chronic Lymphocytic Leukemia",
"Other Lymphocytic Leukemia","Acute Myeloid Leukemia",
"Chronic Myeloid Leukemia","Other Myeloid/Monocytic Leukemia",
"Acute Monocytic Leukemia","Other Acute Leukemia",
"Aleukemic, subleukemic and NOS"),
tot_count = c(162,1816,617,262,644,347,
995,572,376,244,1599,2104,902,1730,646,1762,427,
928,393,502,2029,858,790,2516,900,2399,785,
478,637,4906,294,282,363,395,1135,1836,193,835,
105,4831,2023,2886,516,2032,265,1691,821,182,235,
197,334)
)