按以下划线分隔的值对数据进行透视

Pivot data by values separated by underscrores

我想转换如下所示的数据:

library(dplyr)  

Data <- tibble(
      UID = c("VD3_HC45_T4839374", "KT6_TU45_T7837047","DE45_BH3_T9477277"),
      Merged = c("HB2_JN5", "HY38_BV3_NM43_JH56","WQ5_PI4"))
      

对此:

Output <- tibble(
      UID = c("VD3_HC45_T4839374", "VD3_HC45_T4839374", "KT6_TU45_T7837047", "KT6_TU45_T7837047", "KT6_TU45_T7837047", "KT6_TU45_T7837047","DE45_BH3_T9477277","DE45_BH3_T9477277"),
      Unmerged = c("HB2", "JN5", "HY38","BV36","NM43","JH56","WQ5","PI4"))

我看过 pivot_longer,但找不到用下划线分隔合并值的解决方案

我们可以使用separate_rows

library(tidyr)
separate_rows(Data, Merged)