0

I am getting this error while manipulating a dataframe in r function. The code is shown below:

daysMaintenance <- function(tid, make, component){

      df <- read.csv(paste(sep="","normal/turbine_",tid,"_running.csv"),header=T)


  check_date <- "2008-11-1"

  df <- df[,c("Time_min")]

  df <- df %>% mutate(Day = as.integer(Time_min/1445) + 1)
  df <- df %>% group_by(Day) %>% summarise_at(vars(c(Time_min)), funs(max))

  df <- df %>% mutate(Date = (as.Date(check_date) + df$Day - 1))

  full.list = seq(from = as.Date(min(df$Date)), to = as.Date(max(df$Date)), by = 1)

  diffs <- full.list[!full.list %in% df$Date]
  diffs <- data.frame(diffs)
  colnames(diffs) <- c("no_data_Date") 
  return (diffs)
}

Why do I get this error and how to resolve it? Thank you in advance.

Arch Desai
  • 191
  • 1
  • 8
  • 1
    Maybe you could reduce the code to the relevant part and provide reproducible data with `dput()` –  Nov 11 '19 at 20:48
  • 1
    `df <- df[,c("Time_min")]` turns `df` into a vector. The `dplyr` functions you're using require data frames, which `df` no longer is, hence the error message that you're calling `mutate` on a vector – camille Nov 11 '19 at 21:14
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Nov 11 '19 at 21:26
  • @camille Thank you so much. – Arch Desai Nov 11 '19 at 23:11

0 Answers0