Expand / insert new rows into a data frame based on the value of a discrete variable

Asked

Viewed 18 times

2

I have a data frame with summarized data volumes of a certain product configuration. I need to expand the lines according to the "volume" variable of each summarized line. I tried using add_row() but it didn’t work. Someone can help me?

[Data Frame Example] (https://docs.google.com/spreadsheets/d/1dqVD-Ntxt20bRc_QnX26cl-B46QL8xlh2oV8apCbWew/edit?usp=sharing)

  group_by(grupo, pedido, mod, ver, serie, all_merc, all_esp, cor_ext, cor_int, grupo_opc) %>%
  ungroup() %>% 
  add_row(grupo = grupo,
          cod_prod = cod_prod,
          cod_ver = cod_ver,
          cod_esp = cod_esp,
          ce_prod = ce_prod,
          rev_prod = rev_prod,
          agrupamento = agrupamento,
          volume = seq_along(volume))

Error output: Error in eval_tidy(xs[[j]], mask) : objeto 'grupo' não encontrado

inserir a descrição da imagem aqui

1 answer

3


The problem can be solved in a line of code:

output <- input[rep(row.names(input), input$volume), ]
  • 1

    Thank you so much, you are a monster! God bless you and multiply your knowledge exponentially! Gratitude!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.