0

Knitting of the R markdown halted when it reached the code below and threw the error message below.

# Calculate average duration in minutes by user type and trip duration

bike_data$average_duration_minutes <- ave(bike_data$trip_in_minutes,
                                          list(bike_data$user_type,
                                               bike_data$trip_in_minutes), 
                                          FUN = mean)

I keep getting this error message when I try to knit the R markdown, please help.

Error in split. Default(x, g) : group length is 0 but data length > 0 Calls: ... eval -> eval -> ave -> lapply -> split -> split.default Execution halted.

I tried to check the code for typo error but everything seems ok. But I keep getting the same error. Any help will be appreciated.

neilfws
  • 32,751
  • 5
  • 50
  • 63
  • Please provide https://en.wikipedia.org/wiki/Minimal_reproducible_example#:~:text=In%20computing%2C%20a%20minimal%20reproducible,to%20be%20demonstrated%20and%20reproduced. – Julian Karch Jun 28 '23 at 23:24
  • 1
    Referring to a non-existing column is one way to summon that error, i.e. try `ave(mtcars$mpg, mtcars$mpg, mtcars$imnothere)`. Are you sure about `user_type` and `trip_in_minutes` ? Also keep in mind that knit starts from a clean environment, so the state of your current interactive session and objects visible in RStudio Evironment pane may be quite different compared to knit environment. R session restart would be a good starting point for debugging this and preparing a reproducible example. For reprex check https://stackoverflow.com/tags/r/info & https://stackoverflow.com/q/5963269/646761 – margusl Jun 29 '23 at 07:58
  • This point from @margusl is really important: *"Also keep in mind that knit starts from a clean environment, so the state of your current interactive session and objects visible in RStudio Evironment pane may be quite different compared to knit environment."* It means that if you've created a variable in your console, or in a different script, it won't be present in the knit environment. – C. Murtaugh Jun 29 '23 at 21:52

0 Answers0