My test data:
df = structure(list(field_name = c("fruit1", "fruit2"), field_label = c("Yellow fruits",
"Green fruits"), value = c("1, Pineapple | 2, Mango | 3, Peach",
"1, Lemon | 2, Apple")), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -2L))
I need to separate the value column based on the pipe delimiter and create multiple lines (pivot_longer) but considering that the each value has a number that i would like to append to the field_name
My desired output:
df_out=structure(list(field_name = c("fruit1_1", "fruit1_2", "fruit1_3",
"fruit2_1", "fruit2_2"), field_label = c("Yellow fruits", "Yellow fruits",
"Yellow fruits", "Green fruits", "Green fruits"), value = c("Pineapple",
"Mango", "Peach", "Lemon", "Apple")), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -5L))

