base R
.
-, . , dat <- read.csv("file.csv")
.
dat <-
structure(list(Id = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L), .Label = c("a", "b"), class = "factor"), TagNo = structure(c(3L,
1L, 4L, 2L, 6L, 5L, 9L, 8L, 7L, 10L), .Label = c("A-A-1", "A-A-2",
"A-A-3", "A-A-5", "AX-33", "AX-45", "B-B-3", "B-B-4", "B-B-5",
"BX-B2"), class = "factor"), Nth = c(3L, 3L, 3L, 3L, 3L, 3L,
4L, 4L, 4L, 4L)), .Names = c("Id", "TagNo", "Nth"), class = "data.frame", row.names = c(NA,
-10L))
R
.
dat2 <- do.call(rbind, lapply(split(dat, dat$Nth), function(x)
x[c(1 + (1:(nrow(x) %/% x[1, "Nth"]) - 1)*x[1, "Nth"]), ]))
row.names(dat2) <- NULL
dat2