Вот один способ использования базы R, предполагая, что значение 4-й строки A
равно 42 (а не 43).
#Find out row indices where difference of A value for N + 1 row and
#B value in N row is not equal to 1.
inds <- which(tail(df$A, -1) - head(df$B, -1) != 1)
#Create a dataframe which we want to insert in the current dataframe
#using values from A and B colummn and inds indices
include_df <- data.frame(A = df$B[inds] + 1,B = df$A[inds + 1] - 1, C = 'other',
stringsAsFactors = FALSE)
#Repeat rows at inds to make space to insert new rows
df <- df[sort(c(seq_len(nrow(df)), inds)), ]
#Insert the new rows in their respective position
df[inds + seq_along(inds), ] <- include_df
#Remove row names
row.names(df) <- NULL
df
# A B C
#1 1 2 Background
#2 3 19 Background
#3 20 25 other
#4 26 41 person
#5 42 69 person
#6 70 82 other
#7 83 97 Background
#8 98 106 other
#9 107 129 Background
#10 130 131 other
#11 132 179 Background
#12 180 188 other
#13 189 235 Background
#14 236 242 other
#15 243 258 Background
#16 259 260 other
#17 261 279 person
data
df <- structure(list(A = c(1, 3, 26, 42, 83, 107, 132, 189, 243, 261
), B = c(2L, 19L, 41L, 69L, 97L, 129L, 179L, 235L, 258L, 279L
), C = c("Background", "Background", "person", "person", "Background",
"Background", "Background", "Background", "Background", "person"
)), row.names = c(NA, -10L), class = "data.frame")