Trying to sort a dataframe with time series of stock betas. Would like to create two portfolios, one with stocks that have higher than median beta, and another with lower than median beta for each month. I need to do this row-wise, as each row is a new month.
This is what i have tried so far. not working... I've removed Names which in our dataset is the variable containing dates. Then i have converted characters to NA, and lastly trying to get a new column with median values for each row.
Have not started sorting yet, no idea where to begin here.
Thanks for any help.
My data looks like this:
OMXCB_END_MED <- OMXCB_END %>%
select(-Names) %>%
mutate(across(where(is.character), ~na_if(.,"N/A"))) %>%
rowwise() %>%
mutate(median = median(across(cols = everything()), na.rm = TRUE))