如何从列表中包含的向量中提取索引?

时间:2017-06-26 14:34:33

标签: r list vector indexing

当值满足ifelse的条件时,我尝试从okresy提取索引。以下结果表明,lapply循环让我感到困惑。什么是这些提升的大数字,以及如何从列表中提取每个向量中的索引?

 okresy <- list(okres96, okres97, okres98, okres99, okres00, okres01, okres02, okres03, okres04, okres05, okres06, okres07, okres08, okres09, okres10, okres11, okres12, okres13, okres14, okres15, okres16, okres17)

day1 <- "1996-05-31" 
day2 <- "2012-05-02" 

day1 <- as.Date(day1, "%Y-%m-%d")
day2 <- as.Date(day2, "%Y-%m-%d")

values <- lapply(okresy, function(x) ifelse(day1 <= x & x <= day2, x, 0))
values

结果:

    [[1]]
  [1]    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0
 [35]    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0
 [69]    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0
[103]    0    0 9647 9650 9651 9652 9654 9657 9658 9659 9660 9661 9664 9665 9666 9667 9668 9671 9672 9673 9674 9675 9678 9679 9680 9681 9682 9685 9686 9687 9688 9689 9692 9693
[137] 9694 9695 9696 9699 9700 9701 9702 9703 9706 9707 9708 9709 9710 9713 9714 9715 9716 9717 9720 9721 9722 9724 9727 9728 9729 9730 9731 9734 9735 9736 9737 9738 9741 9742
[171] 9743 9744 9745 9748 9749 9750 9751 9752 9755 9756 9757 9758 9759 9762 9763 9764 9765 9766 9769 9770 9771 9772 9773 9776 9777 9778 9779 9780 9783 9784 9785 9786 9787 9790
[205] 9791 9792 9793 9794 9797 9798 9799 9800 9804 9805 9806 9807 9808 9812 9813 9814 9815 9818 9819 9820 9821 9822 9825 9826 9827 9828 9829 9832 9833 9834 9835 9836 9839 9840
[239] 9841 9842 9843 9846 9847 9848 9849 9850 9853 9854 9860 9861

[[2]]
  [1]  9863  9864  9867  9868  9869  9870  9871  9874  9875  9876  9877  9878  9881  9882  9883  9884  9885  9888  9889  9890  9891  9892  9895  9896  9897  9898  9899  9902
 [29]  9903  9904  9905  9906  9909  9910  9911  9912  9913  9916  9917  9918  9919  9920  9923  9924  9925  9926  9927  9930  9931  9932  9933  9934  9937  9938  9939  9940
 [57]  9941  9944  9945  9946  9947  9948  9952  9953  9954  9955  9958  9959  9960  9961  9962  9965  9966  9967  9968  9969  9972  9973  9974  9975  9976  9979  9980  9981
 [85]  9986  9987  9988  9989  9990  9993  9994  9995  9996  9997 10000 10001 10002 10003 10004 10007 10008 10009 10011 10014 10015 10016 10017 10018 10021 10022 10023 10024
[113] 10025 10028 10029 10030 10031 10032 10035 10036 10037 10038 10039 10042 10043 10044 10045 10046 10049 10050 10051 10052 10053 10056 10057 10058 10059 10060 10063 10064
[141] 10065 10066 10067 10070 10071 10072 10073 10074 10077 10078 10079 10080 10081 10084 10085 10086 10087 10091 10092 10093 10094 10095 10098 10099 10100 10101 10102 10105
[169] 10106 10107 10108 10109 10112 10113 10114 10115 10116 10119 10120 10121 10122 10123 10126 10127 10128 10129 10130 10133 10134 10135 10136 10137 10140 10141 10142 10143
[197] 10144 10147 10148 10149 10150 10151 10154 10155 10156 10157 10158 10161 10162 10163 10164 10165 10168 10169 10170 10171 10172 10177 10178 10179 10182 10183 10184 10185
[225] 10186 10189 10190 10191 10192 10193 10196 10197 10198 10199 10200 10203 10204 10205 10206 10207 10210 10211 10212 10213 10214 10217 10218 10219 10224 10225 10226

(...)

0 个答案:

没有答案