R - creating rows based upon counter value

前端 未结 5 1948
一个人的身影
一个人的身影 2021-01-26 22:22
input <- read.table(header=F, text=\"abc 2 
                def 3 
                pq 2\")
colnames(input) <- c(\"text\",\"count\")

I have input

5条回答
  •  独厮守ぢ
    2021-01-26 23:11

    Or

    as.data.frame(lapply(input, function(x) rep(x, input$count)))
    #   text count
    # 1  abc     2
    # 2  abc     2
    # 3  def     3
    # 4  def     3
    # 5  def     3
    # 6   pq     2
    # 7   pq     2
    

提交回复
热议问题