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