-1
library(dplyr)
library(plotly)
library(lubridate)

googlesearch <- read.csv("multiTimeline.csv", header = FALSE, stringsAsFactors = FALSE)

googlesearch2 <- googlesearch [-1, ]
googlesearch2 <- googlesearch2 [-1, ]
colnames(googlesearch2)[1] <- 'Date' 
colnames(googlesearch2)[2] <- 'NumberofSearch'

googlesearch2$Date <- as.Date(googlesearch2$Date) 
googlesearch2 <- googlesearch2 %>%
  filter(Date > "2015-01-04" & Date < "2018-05-27")

googlesearch3 <- googlesearch2 %>%
  transform(googlesearch2$Date, Date = as.Date(as.character(Date), "%Y-%m-%d"))
googlesearch3 <- googlesearch2 %>%  
  mutate(month = format(Date, "%m"), year = format(Date, "%Y")) %>%
  group_by(Date, yearMon = as.yearmon(Date, "%m-%d-%Y"))

googlesearch3$Date <- as.numeric(googlesearch3$NumberofSearch)

googlesearch3 <- googlesearch3 %>%  
  mutate(month = format(Date, "%m"), year = format(Date, "%Y")) %>%
  group_by(Date, yearMon = as.yearmon(Date, "%m-%d-%Y")) %>%
  summarise(NumberofSearch_sum = sum(NumberofSearch))

data <- tbl_df(googlesearch3)

data %>%
  group_by(yearMon) %>%
summarise(NumberofSearch_mon = sum(NumberofSearch))

I know this is messy. I'm getting this error and I don't know why.Adding the sample code.

Error in summarise_impl(.data, dots) : 
  Evaluation error: invalid 'type' (character) of argument.
sai saran
  • 737
  • 9
  • 32
  • `googlesearch3$Date <- as.numeric(googlesearch3$NumberofSearch)` double check that line. were you trying to convert `NumberofSearch` to numerica? it looks like you converted `Date` to numeric – Wally Ali Nov 19 '18 at 06:56
  • Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Nov 19 '18 at 09:28

1 Answers1

1

In lack of a reproducible example, try to replace the last code chunk of you sample code with:

library(hablar)

data %>%
  retype() %>%
  group_by(yearMon) %>%
  summarise(NumberofSearch_mon = sum(NumberofSearch))

Maybe it works :)

davsjob
  • 1,882
  • 15
  • 10