0
Multiserver <- function(Arrivals, ServiceTimes, NumServers = 1) {
  if (any(Arrivals <= 0 | ServiceTimes <= 0) || NumServers <= 0){
    stop("Arrivals, ServiceTimes must be positive & NumServers must be positive" )
  }
  if (length(Arrivals) != length(ServiceTimes)){
    stop("Arrivals and ServiceTimes must have the same length")
  }
NumCust = length(Arrivals) 
AvailableFrom <- rep(0, NumServers)
ChosenServer <- ServiceBegins <- ServiceEnds <- rep(0, NumCust)  
for (i in seq_along(Arrivals)){
  # go to next available server
  avail <-  min(AvailableFrom)
  ChosenServer[i] <- which.min(AvailableFrom)
  # service begins as soon as server & customer are both ready
  ServiceBegins[i] <- max(avail, Arrivals[i])
  ServiceEnds[i] <- ServiceBegins[i] + ServiceTimes[i]  
  # server becomes available again after serving ith customer
  AvailableFrom[ChosenServer[i]] <- ServiceEnds[i]
}
out <- data.frame(Arrivals, ServiceBegins, ChosenServer, ServiceEnds)
  return(out)

In this code, if I want to change data.frame() to tibble() in the last line of code " out <- data.frame(Arrivals, ServiceBegins, ChosenServer, ServiceEnds) "

Are there any other things I need to change? not just change data.frame() to tibble() ?

Because as I know, differences between dataframe and tibble are the way to show the data.

Thanks for the advice in advance

moodymudskipper
  • 46,417
  • 11
  • 121
  • 167
심준호
  • 41
  • 6
  • Here are a few resources which may help you. https://jtr13.github.io/cc21fall1/tibble-vs.-dataframe.html https://stackoverflow.com/questions/64856424/what-are-the-differences-between-data-frame-tibble-and-matrix – Kitswas Oct 01 '22 at 06:45
  • 2
    This blogpost is good. I'll add that tibbles don't support row names. The linked stack overflow answer is wrong about tibbles. In short tibbles are enhanced data frames, but they're data frames. They do print differently but there are a few other differences designed to make them less surprising than standard data frames. If you do rely on those data frame quirks, like partial matching, drop = TRUE etc your code might break – moodymudskipper Oct 01 '22 at 10:10
  • @moodymudskipper Thank you for the answer!! :) But I'm still figuring out what should I change in that code if I change data.frame() to tibble() Can I get some advice for this problem?! Thanks – 심준호 Oct 02 '22 at 04:40
  • @Kitswas Thank you so much ! I'll have a look at it ! – 심준호 Oct 02 '22 at 04:41
  • You need to change nothing to your code shown here, just replace data.frame by tibble, but your code that uses the object later might behave differently if you use partial matching or other things detailed in the blog post – moodymudskipper Oct 02 '22 at 09:28
  • @moodymudskipper Thank you for the comment :) I just added library to use tibble ! Thank you for the advice. I'll check about partial matching – 심준호 Oct 03 '22 at 10:56

0 Answers0