Attempting to collapse two rows into a singular row.

Hey, as the title states I need to collapse two rows into a singular row, I found some code on
stack overflow and tweaked it.
As a side note I need to do basically the exact same thing as this but with 5 categories as well. I tried to use a suggested method for 2+ rows but I understood it less than this one.

aggregate(data_chemistry_code_sum, list(Group=replace(rownames(chem), rownames(chemistry) %in% c("chem","chemistry"), "chemistry")), sum)


This code gets the error
Error in rownames(chem) : object 'chem' not found

An image of my data is posted below

Any help would be appreciated!

We can't copy from an image, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

example_df <- data.frame(
  share = c(26L, 511L),
  realw = c(1L, 45L),
  link = c(1L, 35L),
  frcst = c(0L, 17L),
  eval = c(13L, 148L),
  gener = c(15L, 161L),
  check = c(10L, 75L),
  clari = c(7L, 9L),
  conn = c(0L, 0L),
  cntex = c(0L, 0L),
  repre = c(0L, 4L),
  const = c(0L, 15L),
  reqst = c(0L, 5L),
  expl = c(0L, 20L),
  chall = c(0L, 3L),
  other = c(0L, 0L),
  ncd = c(0L, 23L),
  Total = c(73, 1071)
)
library(tidyverse)
summarise_all(example_df,sum)

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

Okay, I think I got REPREX to work, heres the output.
data.frame(
share = c(26L, 511L),
realw = c(1L, 45L),
link = c(1L, 35L),
frcst = c(0L, 17L),
eval = c(13L, 148L),
gener = c(15L, 161L),
check = c(10L, 75L),
clari = c(7L, 9L),
conn = c(0L, 0L),
cntex = c(0L, 0L),
repre = c(0L, 4L),
const = c(0L, 15L),
reqst = c(0L, 5L),
expl = c(0L, 20L),
chall = c(0L, 3L),
other = c(0L, 0L),
ncd = c(0L, 23L),
Total = c(73, 1071)
)