I have the above dataframe in R. I wish to be able to create a new column, "month" in this dataframe that will hold the numeric value of the month in question. E.g. for row 1, month_Feb is 1, so month will be 2. For row 2, month_Apr is 1, so month will be 4. I cannot think of an efficient vectorized way to do this in R, as I am quite new to it (having previously used python).
My current solution is to create a list of the months, loop through it for each row, find where the value of 1 is, and add the corresponding numeric month to the "month" column, which is clearly not efficient.
I am doing this in order to fit a linear regression on this dataset, which (to my knowledge) would involve needing to handle the dummy month variables, hence this question. If there is a better way to handle this dummy variable than my approach, please do let me know as well.
Thanks.