I have a data frame which contains some data entry errors.
I wish to replace these outlier values per group with the most common value per group.
My data looks as follows:
df <- data.frame(CODE = c("J1745","J1745","J1745","J1745","J1100","J1100","J1100","J1100","J1100","J1100"),NDC = c(1234,1234,1234,1234,5678,5678,5678,5678,5678,5678),DOSAGE = c("10ML","10 ML","10 ML","10 ML","5 ML","5 ML","5 ML","5 ML","50 ML","5 ML"),DESC = c("TEXT1","TEXT 1","TEXT 1","TEXT 1","TEXT 2","TEXT 2","TEXT 2","TEXT 2","TEXT 10","TEXT 2")) As you can see my DOSAGE and DESC columns contain some inconsistencies and I would like to replace them with the most common value within each group.
My desired output looks as follows:
https://stackoverflow.com/questions/66739165/replace-data-entry-errors-with-the-most-common-value-dplyr March 22, 2021 at 09:06AM

没有评论:
发表评论