library(dplyr); library(magrittr)
ships = c("GoodShip", "Enterprise", "BattleStar", "Caine", "Reliant")

Type = c("Instream", "Instream", "Pier", "Pier", "Instream")

Dat = data.frame(Ships = ships, Type = Type)

Dynamic Renumbering Kernel

Here’s the dynamic renumbering code snippet. It is possibly the least elegant piece of code I’ve ever written. However, if it’s ugly and it works, it can’t be that ugly! We could even wrap this in a function.

For your case, you will just simply want to use reactive variables to update the ‘type’ column.

Order = rep(NA, dim(Dat)[1])

j = 1
for(i in 1:dim(Dat)[1]){
  if(Dat$Type[i] == "Pier"){
    Order[i] = j
    j = j+1
  }
  
}

Ship2 = cbind(Dat, Order)

Ship2 %>% print()
##        Ships     Type Order
## 1   GoodShip Instream    NA
## 2 Enterprise Instream    NA
## 3 BattleStar     Pier     1
## 4      Caine     Pier     2
## 5    Reliant Instream    NA