I have a data set something like this:
df_1 <- tribble(
~id, ~type, ~min_price, ~max_price,
"1", "X", 10, 40,
"1", "Y", 20, 50,
"2", "X", 18, 40,
"2", "Y", 34, 50,
"2", NA, 15, 70,
"3", "X", 40, 90,
"3", "Y", 23, 100,
)
But now, I want to group the data by "id", and then switch the rows to columns. I think this is not something like transpose.
df_1 <- tribble(
~id, ~min_price_X, ~min_price_Y, ~min_price_NA, ~max_price_X, ~max_price_Y, ~max_price_NA,
"1", 10, 10, NA, 40, 50, NA,
"2", 18, 34, 15, 40, 50, 70,
"3", 40, 23, NA, 90, 100, NA,
)
Would you have any suggestion to get this data?
See Question&Answers more detail:
os