input <- read.table(header=F, text=\"abc 2 def 3 pq 2\") colnames(input) <- c(\"text\",\"count\")
I have input
Using data.table
data.table
library(data.table) setDT(input)[, .SD[rep(1:.N, count)]] # text count #1: abc 2 #2: abc 2 #3: def 3 #4: def 3 #5: def 3 #6: pq 2 #7: pq 2
Or
setDT(input)[input[,rep(1:.N, count)]]