I have a dataset as I've shown below:
df_A <- tribble(
~id, ~type, ~min_price, ~max_price,
"1", "X", 10, 40,
"1", "Y", 20, 50,
"1", NA, 15, 70,
"1", "X", 40, 90,
"1", "Y", 23, 100,
"2", "X", 18, 40,
"2", "Y", 34, 50,
"2", "Y", 64, 150,
"2", NA, 15, 70,
"3", "X", 40, 90,
"3", "Y", 23, 100,
)
Now, I want to manipulate the data to answer this question: "When "type" is X, what is the min price for each id?" or "when "type" is Y, what's min price for each id?"
desired_DF <- 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,
)
Could someone help me to get this?