I have a array (option strikes):
550 600 620 640 650 660 680 700 710 720 730 740 750 760 770 780 790 800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990 1000 1010 1020 1030 1040 1050 1060 1070 1080 1090 1100 1110 1120 1130 1140 1150 1160 1170 1180 1190 1200 1210 1220 1230 1240 1250 1260 1270 1280 1290 1300 1310 1320 1330 1340 1350 1360 1370 1380 1390 1400 1410 1420 1430 1440 1450 1460 1470 1480 1490 1500 1520
It has uneven increments sometimes in the beginning or the end. For example, the first number is 550 and it goes to 600 right away from there, a increase of 50 points.
I know that at around a central number (at the money) there exists a subset of the above vector which increments by 10 points. I want to somehow extract it. The central number is 1090 for this vector. It can change continuously for different vectors like the one above - but should be around the center.
So for the above array, I want to extract:
700 710 720 730 740 750 760 770 780 790 800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990 1000 1010 1020 1030 1040 1050 1060 1070 1080 1090 1100 1110 1120 1130 1140 1150 1160 1170 1180 1190 1200 1210 1220 1230 1240 1250 1260 1270 1280 1290 1300 1310 1320 1330 1340 1350 1360 1370 1380 1390 1400 1410 1420 1430 1440 1450 1460 1470 1480 1490 1500
In this vector all numbers increment at a constant rate of 10 points. So essentially I want to be able to subset the first vector for a subset that increments constantly at 10 points. How can I do that?
One way would be too loop. Take the difference between and subset for 10 point differences. But this way is not very elegant as I must set a number to stop looping at. Love to hear if there are better ways.
Thanks
edit:
for the following sequence, julius' answer doesnt seem to work..
700 710 720 730 740 750 760 770 780 790 800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990 1000
1010 1020 1030 1040 1050 1060 1070 1080 1090 1100 1110 1120 1130 1140 1150 1160 1170 1180 1190 1200 1210 1220 1230 1240 1250 1260 1270 1280 1290 1300 1310
1320 1330 1340 1350 1360 1370 1380 1390 1400 1450 1500
I get when I use Julius' answer: 1410 1420 1430 1440 1450 1460 1470 1480 1490 1500 1510 1520 1530 1540 1550 1560 1570 1580 1590 1600 1610 1620 1630 1640 1650 1660 1670 1680 1690 1700 1710 1720 1730 1740 1750 1760 1770 1780 1790 1800 1810 1820 1830 1840 1850 1860 1870 1880 1890 1900 1910 1920 1930 1940 1950 1960 1970 1980 1990 2000 2010 2020 2030 2040 2050 2060 2070 2080 2090 2100 2110
rle(diff(your_vector))
should be helpful. - Gregor Thomasvector
right, not an object of classarray
? - Gregor Thomas