I have a data set something like this:
data <- tribble(
~id, ~value,
'311321 333 333', 20,
'18 939 4244', 0,
'999 3838 4242', 1,
)
Now, I want to get only the first item in id column and then return the variable of value to 1 if it is greater than 0. Here is the desired data:
desired_data <- tribble(
~new_id, ~value, ~new_value,
'311321', 20, 1,
'18', 0, 0,
'999', 1, 1,
)
Any idea how to do it?