I am trying to add a new variable to a data set I am working with in R and the data is time-based and distance based (rally racing). I cannot figure out how to add a variable with conditional data based on another variable, and have it all in the same column.
I can create a new column and add it to the data frame, that is not an issue, but I cannot figure out how to label the data.
For example, I know that 0-2 minutes was mile 1, 2-4 minutes was mile 2, etc. But how can I label the data based on conditions like this? I know SQL, in which case I would use a CASE statement. Is there an equivalent in R? I am hoping to do something like:
CASE
WHEN timeseconds >2 THEN 'mile1'
WHEN timeseconds BETWEEN 2 AND 4 THEN 'mile2'
END AS mile_marker
But I don't know what to do in R to make this work. Would this be a bunch of nested if else statements?