Use expandRows()
from the splitstackshape
package:
library(splitstackshape)
expandRows(df, "freq")
Simple syntax, very fast, works on data.frame
or data.table
.
Result:
var1 var2
1 a d
2 b e
2.1 b e
3 c f
3.1 c f
3.2 c f