firstlastobs.Rd
Locate the index of the first/last unique value in i) a vector or of a variable in a data frame.
lastobs(x, ...)
firstobs(x, ...)
# S3 method for default
lastobs(x, ...)
# S3 method for default
firstobs(x, ...)
# S3 method for formula
lastobs(formula, data = parent.frame(), ...)
# S3 method for formula
firstobs(formula, data = parent.frame(), ...)
A vector
Currently not used
A formula (only the first term is used, see 'details').
A data frame
A vector.
If writing ~a + b + c as formula, then only a is considered.
x <- c(rep(1, 5), rep(2, 3), rep(3, 7), rep(1, 4))
firstobs(x)
#> [1] 1 6 9
lastobs(x)
#> [1] 8 15 19
data(dietox)
firstobs(~Pig, data=dietox)
#> [1] 1 13 25 37 49 61 73 85 97 109 121 133 145 157 169 181 193 205 217
#> [20] 229 241 253 265 277 289 301 312 323 334 346 358 370 382 394 406 418 430 442
#> [39] 454 466 478 490 502 514 526 538 550 562 574 586 598 610 622 634 646 658 670
#> [58] 682 694 706 718 730 742 754 766 778 790 802 814 826 838 850
lastobs(~Pig, data=dietox)
#> [1] 12 24 36 48 60 72 84 96 108 120 132 144 156 168 180 192 204 216 228
#> [20] 240 252 264 276 288 300 311 322 333 345 357 369 381 393 405 417 429 441 453
#> [39] 465 477 489 501 513 525 537 549 561 573 585 597 609 621 633 645 657 669 681
#> [58] 693 705 717 729 741 753 765 777 789 801 813 825 837 849 861