I want to create a new dataframe with one column with the groups and the other with the summed total of the hours.
Here is the code:
<code>library(dplyr)
# pull unique identifiers
unique_mine_ids <- unique(prod[1])
# group by identifier and sum hours
prod_summed <- prod %>%
group_by(MINE_ID) %>%
summarize(HOURS = sum(ANNUAL_HRS))
# new dataframe with unique identifiers and summed hours columns
prod_summed <- mutate(MINE_ID = unique_mine_ids,
HOURS = HOURS)
</code>
<code>library(dplyr)
# pull unique identifiers
unique_mine_ids <- unique(prod[1])
# group by identifier and sum hours
prod_summed <- prod %>%
group_by(MINE_ID) %>%
summarize(HOURS = sum(ANNUAL_HRS))
# new dataframe with unique identifiers and summed hours columns
prod_summed <- mutate(MINE_ID = unique_mine_ids,
HOURS = HOURS)
</code>
library(dplyr)
# pull unique identifiers
unique_mine_ids <- unique(prod[1])
# group by identifier and sum hours
prod_summed <- prod %>%
group_by(MINE_ID) %>%
summarize(HOURS = sum(ANNUAL_HRS))
# new dataframe with unique identifiers and summed hours columns
prod_summed <- mutate(MINE_ID = unique_mine_ids,
HOURS = HOURS)
When I run this, the result is only 1 value (everything summed) and 1 column, instead of one column of the unique ID’s and the second column the sum of the hours.
New contributor
savannah bommarito is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.