I have a question about a problem with my data analysis. I have a large data set with sentiment scores for every day of the week, but I want to add the weekends to the Fridays. This for the reason that I can make stock predictions for the Monday. My idea was to give them the same date and afterwards I aggregate them on daily basis. An example of the relevant part of my data output is:
year: 2019-01-01 2019-01-02 2019-01-03 2019-01-04 2019-01-05 2019-01-06 2019-01-07 UTC" weekday: 1 2 3 4 5 6 7
so the aim is to get the dates of 7(Saturday) & 1(Sunday) equal to that of 6(Friday)
I have tried a couple of codes to realize this:
1)
ifelse(Brexit_data$weekday == '7', as.POSIXct(Brexit_data$year - as.difftime(1, units = "days")), as.POSIXct(Brexit_data$year - as.difftime(0, units = "days")))`
ifelse(Brexit_data$weekday == '7', as.date(Brexit_data$year) -1, as.date(Brexit_data$year))
Both returned a different structure type of the dates like:
[1] 1549065600 1549065600 1549065600 1549065600 1549065600 1549065600 1549065600 1549065600 1549065600 1549065600 1549065600 1549065600 1549065600 1549065600
2)
Brexit_data$year <- Brexit_data$year[Brexit_data$weekday == '7'] - as.difftime(1, units = "days")
Brexit_data$year <- Brexit_data$year[Brexit_data$weekday == '7'] -1
Which returned the following: Error in $<-.data.frame
(*tmp*
, year, value = c(1556755200, 1556755200, : replacement has 4206 rows, data has 29299*
So it can't for some reason not change the variables given the condition.
Stack overflow has always been for me a source of help for finding solutions. Hopefully someone can help me with this problem. Would help me a lot!