创建十进制最大值为 59 的整数序列的优雅方法

Elegant way to create sequence of integers with decadic maximum of 59

你能想出一种优雅的方法来在 R 中创建整数序列,十进制最大值为 59(hmm 序列),具有任意 starting/end 点吗?像这样

715 716 ... 759 800 801 ... 830

使用%%过滤除以100后的余数小于或等于60的数字。

x <- 715:830
x[x %% 100 <= 60]

#  [1] 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
# [17] 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
# [33] 747 748 749 750 751 752 753 754 755 756 757 758 759 760 800 801
# [49] 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
# [65] 818 819 820 821 822 823 824 825 826 827 828 829 830

另一个选项:

x <- 715:830
x[!substr(x, nchar(x) - 1, nchar(x)) > 59]

#  [1] 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
# [17] 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
# [33] 747 748 749 750 751 752 753 754 755 756 757 758 759 800 801 802
# [49] 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
# [65] 819 820 821 822 823 824 825 826 827 828 829 830