I have data of S&P101 built in this way:
Symbol Name X2020.01.02 X2020.01.03 X2020.01.06 X2020.01.07 X2020.01.08 X2020.01.09
1 AAPL Apple 75.0875 74.3575 74.95 74.5975 75.7975 77.4075
2 ABBV AbbVie 89.5500 88.7000 89.40 88.8900 89.5200 90.2100
Now, I turned it into long format because I use mixed model:
#convert data to long format for mixed model
c_data = ncol(data_2020)
#convert the dates into numbers
names(data_2020)[3:c_data]<- 1:(c_data-2)
tempDataLong <- data_2020 %>% gather( key = day, value= close, 3:c_data, factor_key = TRUE )
#convert data to numeric for analysis
tempDataLong$day<- as.numeric(tempDataLong$day)
When I try to use the function as.date to transform the data into dates it does not accept it since it is now a factor, and when I make it numeric first and then change it to irrelevant dates (i.e. 1970)
please note that the dates are not continuous right now, because the stock market does not work three days a week, but for my analysis purposes I'm allowed to use them as such.
My question is- how do I turn the data in my long format back to the dates in the wide format?
Here is how my long format looks like right now:
Symbol Name day close
1 AAPL Apple 1 75.08750
2 ABBV AbbVie 1 89.55000
3 ABT Abbott Laboratories 1 86.95000
4 ACN Accenture 1 210.14999
5 ADBE Adobe 1 334.42999
6 AIG American International Group 1 51.76000
7 AMGN Amgen 1 240.10001
8 AMT American Tower 1 228.50000