I currently have a dataset of 13 variables with 754 unique dates (March 1957 to December 2019). all dates appear a lot of times within the dataset (I have around 3 million observations). And I have to normalize all the variables to a [-1,1] scale by date. I tried using the following code but it normalizes the entire dataset and not by year. I tried looking for a solution but couldn't find any, so I hope you guys can help me.
normalize <- function(x) {
return ((2*(x - min(x, na.rm = TRUE)) / (max(x, na.rm = TRUE) - min(x, na.rm = TRUE)))-1)}
Normalized_data <- Complete_data %>%
group_by(Date) %>%
as.data.frame(apply(Complete_data,2,normalize))