I need to create a multi column table of customer arrival time, customer wait time, service time, and customer leave time. Service time is the time it takes for the cashier to help the customer. Arrival time and service time are provided by a function which uses the rexp command.
The table needs to look like this: table
My code looks like this:
singleTime = function(Rate)
{
data = rexp(1,Rate)
return(data)
}
waitTimes = function(m,arrivalRate,serviceRate)
{
arrivalTimes = c(1:m)
waitTimes = c(1:m)
serviceTimes = c(1:m)
leaveTimes = c(1:m)
previousLeaveTime = 0
for(i in (1:m))
{
arrivalTimes[i] = singleTime(arrivalRate)
if(i == 0)
{
waitTimes[i] = 0
}
else if((previousLeaveTime - arrivalTimes[i])<= 0)
{
waitTimes[i] = 0
}
else
{
waitTimes[i] = leaveTimes[i-1] - arrivalTimes[i]
}
serviceTimes[i] = singleTime(serviceRate)
leaveTimes[i] = waitTimes[i] + serviceTimes[i] + arrivalTimes[i]
previousLeaveTime = leaveTimes[i]
i = i + 1
}
waitTimesTable = table(arrivalTimes,waitTimes,serviceTimes,leaveTimes)
View(waitTimesTable)
}