-1
```Class       Grade
   Physics       8
   Math          7
   English       7.5
   Biology       5 
   Physics       4 
if(Class == Physics) {Sum(Grade)

I am looking that when the Class is similar to what I am searching it takes the Grade next to it. I assume something like this. and it will combine so in this case 12 for physics. And then That I can create a new dataframe where I can combine all the numbers corresponding to the Class.

1 Answers1

0

A data.table solution for this.

df = data.frame(Class = c("Physics", "Math", "English", "Biology", "Physics"),
                Grade = c(8, 7, 7.5, 5, 4))

library(data.table)
setDT(df)
df[, sum(Grade), by =  Class]
ljwharbers
  • 393
  • 2
  • 8