Here’s one solution:
df.expanded <- df[rep(row.names(df), df$freq), 1:2]
Result:
var1 var2
1 a d
2 b e
2.1 b e
3 c f
3.1 c f
3.2 c f
More Related Contents:
- Subset data frame based on number of rows per group
- Drop data frame columns by name
- Convert data.frame columns from factors to characters
- R Reshape data frame from long to wide format? [duplicate]
- Select the first row by group
- Calculate the mean of every 13 rows in data frame
- Select the first and last row by group in a data frame
- Calculate row means on subset of columns
- How does one reorder columns in a data frame?
- Update data frame via function doesn’t work
- R spreading multiple columns with tidyr [duplicate]
- Create a data.frame where a column is a list
- Take random sample by group
- How do I delete rows in a data frame?
- Replacing values from a column using a condition in R
- Split data.frame by value
- Convert data.frame column to a vector?
- Add new row to dataframe, at specific row-index, not appended?
- Growing a data.frame in a memory-efficient manner
- Remove columns from dataframe where some of values are NA
- Splitting a data.frame by a variable [duplicate]
- Check whether values in one data frame column exist in a second data frame
- How do you remove columns from a data.frame?
- Unlist a data frame by rows, not columns
- Using lapply to apply a function over list of data frames and saving output to files with different names
- DT[!(x == .)] and DT[x != .] treat NA in x inconsistently
- Row-wise sum of values grouped by columns with same name
- Divide each value by the sum of values by group
- Convert all data frame character columns to factors
- What you can do with a data.frame that you can’t with a data.table?