If you just want to get the counts, it's simply rowSums(df == 98)
.
If you want to add it as a column, then in base R:
df[, "total"] <- rowSums(df == 98)
df
#> Name Maths Science English History German total
#> 1 Alex 100 98 88 90 89 1
#> 2 Adam 90 100 98 98 98 3
#> 3 James 98 89 90 98 100 2
#> 4 Matt 98 80 100 99 99 1
#> 5 Pat 98 98 98 100 84 3
Or in dplyr
, if you prefer:
library(dplyr)
df %>% mutate(total = rowSums(. == 98))
#> Name Maths Science English History German total
#> 1 Alex 100 98 88 90 89 1
#> 2 Adam 90 100 98 98 98 3
#> 3 James 98 89 90 98 100 2
#> 4 Matt 98 80 100 99 99 1
#> 5 Pat 98 98 98 100 84 3
Here's the data:
txt <- " Name Maths Science English History German
Alex 100 98 88 90 89
Adam 90 100 98 98 98
James 98 89 90 98 100
Matt 98 80 100 99 99
Pat 98 98 98 100 84"
df <- read.table(text = txt, header = TRUE)
Created on 2019-12-14 by the reprex package (v0.2.1)