dplyr left_join with timeline and dates

不羁岁月 提交于 2021-02-08 04:41:21

问题


I want merge data from a filtered set into a timeline I created with the help of the timeline package.

df1 looks like

Date        Label    Freq
2011-03-12  1        18
2011-03-14  1        16
2011-03-18  1        5

time line produces a vector with dates from a specific starting date until a specified end date. What I want to achieve is a timeline with all days in a certain period. Then I want to merge df1 into timeline.

Using left_join from dplyr I first get

Error in UseMethod("left_join") : 
  not applicable for 'left_join' for of object of class "Date"

So I then thought that that I just transform both date colouns into factors by applying as.factor

However, I then end up with

not compatible with STRSXP 

What I basically want to achieve:

I have a large data set. I want to have a shiny application where people can search for a string in the dataset.

I do this by

input$search = 'term to search'
filtplay = filter(vicsecret_sentiment, grepl(input$search, message))

I aggregate the filtered hits by days

filtplay$Date <- as.Date(filtplay$created_time)
summary_df <- as.data.frame(table(filtplay$Date, filtplay$SVM_LABEL))
colnames(summary_df) <- c("Date", "Label", "Freq")
posfil = filter(summary_df, Label == 1)

Now I want to get a timeline that is determined by the user

timeline = seq(as.Date(input$startdate), as.Date(input$enddate), by="days")

And finally I want to match now posfil into the timeline to then plot timeline with for Freq.

However, I do not get the merging.

Any help or idea how to achieve this or how to solve the left_join is really appreciated!

Best thanks beforehand!

来源:https://stackoverflow.com/questions/34909508/dplyr-left-join-with-timeline-and-dates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!