0

I'd appreciate any help, as I'm not getting the diff time I need. Instead I get this error:

In eval_tidy(xs[[i]], unique_output) : NAs introduced by coercion

Here's my code:

db <- dados%>%
   select(Employee, Leaving.Reason, Entry.date.into.Group, Age, time.in.company, Termination.Date, 
   Salary, Promotion.Increase, Valid.Since.Promotion)%>%
   group_by(Employee) %>%
   group_split() %>%
   lapply(function(x) {
      x <- x %>%
  arrange(desc(Salary))

tibble(
  Employee = unique(x$Employee),
  N = nrow(x),
  Time_since_last_promo = as.integer(difftime(max(x$Entry.date.into.Group), 
 max(x$Valid.Since.Promotion),units = "days")),
  N_promo = length(unique(x$Valid.Since.Promotion)),
  timein=as.numeric(as.character(x$time.in.company)),
  reason=x$Leaving.Reason

  )

}) %>%

bind_rows()
miken32
  • 42,008
  • 16
  • 111
  • 154
Maria
  • 11
  • 4
  • 2
    We can't run any of your code without a sample of data, and we can't see any of your output, and you haven't included any explanation of the code itself, and what you've called an error is probably actually a warning but that's unclear without any context. [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that folks can help with. – camille Jan 22 '20 at 15:31
  • its too big the reproducible code, but Im trying to have an idea of how long it takes for a person to get promoted. Im using the time she was last promoted and the time she got into the company and with setdiff I get this error... instead of time I get NA's. I'll try to get a minor example and post here. thanks. – Maria Jan 22 '20 at 15:53
  • 2
    would help to get a small sample of data; but note that you are using `max` in your `difftime` statement...this will give `NA` if there is any `NA` in those variables `Entry.date.into.Group` and `Valid.Since.Promotion)` ... if you don't specify `na.rm = TRUE` in your `max` function, you will get `NA` – Ben Jan 22 '20 at 20:58
  • thanks Ben, Im new to R, this sorted out quite simple ;) – Maria Jan 23 '20 at 13:11
  • 1
    It's a good idea to keep important aspects of the question, such as error messages, in the body of the question. – miken32 Jan 23 '20 at 23:45

0 Answers0