1

I have a dataframe that looks like this

    bin        val
    A-B-C     0.345
    K-P       0.612

I would like to un-bin the data above into the following using R

    bin val
    A   0.345
    B   0.345
    C   0.345
    K   0.621
    P   0.621

I appreciate your suggestions.

Vendetta
  • 294
  • 4
  • 11

1 Answers1

1

I think this is what you want:

library(dplyr)
library(tidyr)

df1 %>%
  separate_rows(bin, sep = "-")

# A tibble: 5 x 2
  bin     val
  <chr> <dbl>
1 A     0.345
2 B     0.345
3 C     0.345
4 K     0.612
5 P     0.612
Anoushiravan R
  • 21,622
  • 3
  • 18
  • 41