The most flexible base R function for reshaping data is reshape. See ?reshape for its syntax.
# create unbalanced longitudinal (panel) data set
set.seed(1234)
df <- data.frame(identifier=rep(1:5, each=3),
location=rep(c("up", "down", "left", &quo...