I have a data frame containing \"name\"
of U.S. Presidents, the years when they start and end in office, (\"from\"
and \"to\"
columns
Use by
to create a by
list L
of data.frames, one data.frame per president, and then rbind
them together. No packages are used.
L <- by(presidents, presidents$name, with, data.frame(name, year = from:to))
do.call("rbind", setNames(L, NULL))
If you don't mind row names then the last line could be reduced to just:
do.call("rbind", L)