Library contents

R append

Insert a group of new stops before a known position on a route.

A simple example

append

  1. Start with A, C
  2. Do this Insert B between them
  3. Result A, B, C
Inserting at the middle shifts C one place to the right.

Syntax

R 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.R

Insert 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.

From the programstops <- append(stops, c("Hall", "Pool"), after = 1)
ResultSchool, Hall, Pool, Depot
Lesson.R
stops <- c("School", "Depot")
stops <- append(stops, c("Hall", "Pool"), after = 1)
cat(paste(stops, collapse = ", "))
Output
School, Hall, Pool, Depot

Hall and Pool are inserted between the school and the depot in pickup order.

Advertisements

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.

GivenFern + Tide, Sky
Worked resultFern · Tide · Sky

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.

GivenLens, Stand + Cable
Worked resultLens · Stand · Cable

What to watch for

after counts the existing elements that precede the inserted values. Save the vector returned by append.

Documentation for append