Generally, when questions come up about "how do I preserve the order of...", I try factor
as one of the first solutions and specify the desired order of my factor
s:
mydat$var1 <- factor(mydat$var1, c("john", "aron", "frank"))
mydat$var2 <- factor(mydat$var2, c("john", "aron", "frank"))
acast(mydat, var1~var2)
# Using var3 as value column: use value.var to override.
# john aron frank
# john 0.464706 1.77877633 0.5925874
# aron NA 0.04940059 -0.3180871
# frank NA NA -1.3888493