\begin{Schunk}
\begin{Sinput}
 for(i in 7:2){
     gpa[ , paste0("gpa", i)] <- gpa[ , paste0("gpa", i-1)]
  }
 gpa$gpa1 <- NULL
 for(i in 7:2){
     gpa[ , paste0("job", i)] <- gpa[ , paste0("job", i-1)]
  }
 gpa$job1 <- NULL
 colnames(gpa)
\end{Sinput}
\begin{Soutput}
 [1] "student"  "gpa2"     "job2"     "gpa3"     "job3"     "gpa4"     "job4"     "gpa5"    
 [9] "job5"     "gpa6"     "job6"     "sex"      "highgpa"  "admitted" "gpa7"     "job7"    
\end{Soutput}
\begin{Sinput}
 gpa4 <- reshape(gpa, varying = list(paste0("job", 2:7), paste0("gpa", 2:7)), 
                  v.names = c("job", "gpa"),  direction = "long", 
                  idvar = "student") 
 gpa4 <- gpa4[order(gpa4$student, gpa4$time), ]
 head(gpa4, 12)
\end{Sinput}
\begin{Soutput}
    student    sex highgpa admitted time     job gpa
1.1       1 female     2.8      yes    1 2 hours 2.3
1.2       1 female     2.8      yes    2 2 hours 2.1
1.3       1 female     2.8      yes    3 2 hours 3.0
1.4       1 female     2.8      yes    4 2 hours 3.0
1.5       1 female     2.8      yes    5 2 hours 3.0
1.6       1 female     2.8      yes    6 2 hours 3.3
2.1       2   male     2.5       no    1 2 hours 2.2
2.2       2   male     2.5       no    2 3 hours 2.5
2.3       2   male     2.5       no    3 2 hours 2.6
2.4       2   male     2.5       no    4 2 hours 2.6
2.5       2   male     2.5       no    5 2 hours 3.0
2.6       2   male     2.5       no    6 2 hours 2.8
\end{Soutput}
\end{Schunk}
