R max
Choose the larger of the reserved count and the current seating target.
A simple example
max
- Start with 2 and 5
- Do this Choose the larger value
- Result 5
cat(max(2.0, 5.0), "\n", sep = "")
5
Syntax
max(booked, capacity)
Run these examples in R
Save one example at a time as Lesson.R. Use R 4.x.
Rscript --vanilla Lesson.RKeep enough seats for a booking
A booking screen receives a requested party size and the current seat inventory. Use the available capacity to decide how many places can actually be assigned.
booked <- 18.0
capacity <- 20.0
cat(sprintf("%.3f\n", max(booked, capacity)))
20.000
Eighteen bookings and a seating target of twenty require planning for twenty places.
Record the busiest hour at a help desk
A help desk is planning coverage for its busiest period. Compare the recorded hourly loads to identify the peak that the next shift needs to handle.
baseline <- 15.0
current <- 23.0
cat(sprintf("%.3f\n", max(baseline, current)))
23.000
The current count of 23 exceeds the previous record of 15.
Keep the busiest counter reading
A librarian has recorded a peak of 17 checkouts in an hour. The current hour reaches 21 and the dashboard refreshes its peak.
Taking the greater count updates the peak only when demand rises.
What to watch for
This selects one value. Adding both would count overlapping demand twice.