0

How do I check if the student have achieve higher marks in "Grade2" compared to their previous grade in "Grade1"

df = data.frame(Grade1 = c("5","1","7","6"), 
            Grade2 = c("4", "5", "10", "10"))
df

rownames(df) = c("StudentA","StudentB","StudentC","StudentD")
df
Dreammmm
  • 45
  • 5

1 Answers1

0

Make sure you fix you dataframe to contain integers and not strings.

This will work:

df = data.frame(Grade1 = c(5,1,7,6), 
                Grade2 = c(4, 5, 10, 10))

rownames(df) = c("StudentA","StudentB","StudentC","StudentD")

mask <- df$Grade2 > df$Grade1
rownames(df[mask,])

Output:

[1] "StudentB" "StudentC" "StudentD"
j__carlson
  • 1,346
  • 3
  • 12
  • 20