I have a set of students c("John","Jeff","Jim","Jack","Joe","Jones") and each of them has attended in 3 different classes c("Math","Science","History") and achieved an natural number as score between 0 and 100.
Therefore, the table is supposed to be like
Name Class   Score
Jim  Math     25
Jim  History  60
Jim  Science  80
Jeff Math     85
Jeff History  40
Jeff Science  100
...
...
...
What i have tried is:
dt<-data.frame(
  Names=rep(c("John","Jeff","Jim","Jack","Joe","Jones"),3 ),
  Class=rep(c("Math","Science","History"),6  ),
  Grades=sample(1:100,18  ))
dt[sort(dt$Names),]
My code gives me:
   Names   Class Grades
4   Jack    Math     73
10  Jack    Math     87
16  Jack    Math     81
2   Jeff Science     24
8   Jeff Science     79
so, instead of Math, History, and Science, i have Math, Math, and Math.
But, it does not give me what i need. How can i fix it?
 
    