Grouping data_tidying data

Please i need help to tidy up my data
(icecream <- readRDS(url("https://ecnp003.netlify.app/data/icecream.rds"))

by grouping it into two. I would like to group the temperature based on its distinct value as one set of data and the remainder as another set of data.

The total revenue on both sets (the distinct value set and the second set ) should be equal to the total revenue on the complete set.

I have used the following command to get the distinct value but i am not sure of the completeness.

distinct_Table <- distinct(icecream, temperature, .keep_all=TRUE)

Why would you expect that splitting the data in the way you describe would result in equality between the sums of the split sets ? That seems unlikely...

library(dplyr)

(exdf_1 <- data.frame(
  code = rep(letters[1:5],2),
  val = 1:10
))

(one_half <- distinct(exdf_1,code,.keep_all = TRUE))
(other_half <- setdiff(exdf_1,one_half))

sum(one_half$val)
sum(other_half$val)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.