Figured out Kgroup code - now stand alone in "KgroupDGM.R"