R append
Insert a group of new stops before a known position on a route.
A simple example
append
- Start with A, C
- Do this Insert B between them
- Result A, B, C
Syntax
append(stops, extras, after = position)
Run these examples in R
Save one example at a time as Lesson.R. Use R 4.x.
Rscript --vanilla Lesson.RInsert two pickup stops before the depot
A shuttle normally travels straight from the school to the depot. The dispatcher adds two afternoon pickups and needs them to appear in the supplied order before the final stop.
stops <- c("School", "Depot")
stops <- append(stops, c("Hall", "Pool"), after = 1)
cat(paste(stops, collapse = ", "))
School, Hall, Pool, Depot
Hall and Pool are inserted between the school and the depot in pickup order.
Extend a reading list
A class has chosen one novel and adds two more titles. The desk adds the new entries after the existing ones. Read the resulting sequence in its recorded order.
Update an equipment checklist
A technician adds the final item after packing two pieces of equipment. The desk adds the new entries after the existing ones. Read the resulting sequence in its recorded order.
What to watch for
after counts the existing elements that precede the inserted values. Save the vector returned by append.