[R] Problem with which function
max
uni at maxmetzger.de
Fri Oct 12 12:31:29 CEST 2012
Hej,
i need the which() funktion to find the positions of an entry in a matrix.
the entries i'm looking for are : seq(begin,end,0.01) and there are no
empty spaces
i'm searching in the right range.
so i was looking for the results R can find and i recieved this answer.
for (l in
1:length(qr)){print(c(l,nstu[l,1],nsto[l,1],nsto[l,1]-nstu[l,1],(nsto[l,1]-nstu[l,1])*100,which(sp1[,1]==nstu[l,1]),(nsto[l,1]-nstu[l,1])*100+which(sp1[,1]==nstu[l,1]),which(r[,1]==nstu[l,1]),(nsto[l,1]-nstu[l,1])*100+which(r[,1]==nstu[l,1])))}
[1] 1 0 0 0 0
[1] 2 0 0 0 0
[1] 3 0 0 0 0
[1] 4.00 87.34 87.97 0.63 63.00 2491.00 2554.00 2491.00 2554.00
[1] 5.00 86.73 88.46 1.73 173.00 2430.00 2603.00
[1] 6.00 86.22 88.77 2.55 255.00 2379.00 2634.00
[1] 7.00 85.77 89.01 3.24 324.00 2334.00 2658.00
[1] 8.00 85.36 89.22 3.86 386.00 2293.00 2679.00
[1] 9.0 85.0 89.4 4.4 440.0 2257.0 2697.0
[1] 10.00 84.68 89.57 4.89 489.00 2225.00 2714.00 2225.00 2714.00
[1] 11.00 84.38 89.73 5.35 535.00 2195.00 2730.00
[1] 12.00 84.11 89.88 5.77 577.00 2168.00 2745.00
[1] 13.00 83.86 90.02 6.16 616.00 2143.00 2759.00
[1] 14.00 83.64 90.15 6.51 651.00 2121.00 2772.00
[1] 15.00 83.43 90.28 6.85 685.00 2100.00 2785.00 2100.00 2785.00
[1] 16.00 83.24 90.40 7.16 716.00 2081.00 2797.00
[1] 17.00 83.07 90.52 7.45 745.00
[1] 18.00 82.91 90.63 7.72 772.00 2048.00 2820.00
[1] 19.00 82.76 90.75 7.99 799.00 2033.00 2832.00
[1] 20.00 82.62 90.86 8.24 824.00 2019.00 2843.00 2019.00 2843.00
[1] 21.00 82.49 90.97 8.48 848.00 2006.00 2854.00
[1] 22.00 82.37 91.08 8.71 871.00 1994.00 2865.00 1994.00 2865.00
[1] 23.00 82.26 91.19 8.93 893.00 1983.00 2876.00
[1] 24.00 82.16 91.31 9.15 915.00 1973.00 2888.00
[1] 25.00 82.07 91.42 9.35 935.00 1964.00 2899.00
[1] 26.00 81.98 91.53 9.55 955.00 1955.00 2910.00
[1] 27.00 81.90 91.64 9.74 974.00 1947.00 2921.00 1947.00 2921.00
[1] 28.00 81.83 91.75 9.92 992.00 1940.00 2932.00
[1] 29.00 81.76 91.87 10.11 1011.00 1933.00 2944.00
[1] 30.00 81.69 91.98 10.29 1029.00 1926.00 2955.00
[1] 31.00 81.63 92.09 10.46 1046.00 1920.00 2966.00
[1] 32.00 81.57 92.20 10.63 1063.00
[1] 33.00 81.50 92.31 10.81 1081.00 1907.00 2988.00
[1] 34.00 81.44 92.43 10.99 1099.00 1901.00 3000.00
[1] 35.00 81.38 92.54 11.16 1116.00 1895.00 3011.00
[1] 36.00 81.31 92.65 11.34 1134.00 1888.00 3022.00
[1] 37.00 81.25 92.76 11.51 1151.00 1882.00 3033.00
[1] 38.00 81.18 92.87 11.69 1169.00 1875.00 3044.00 1875.00 3044.00
[1] 39.00 81.12 92.98 11.86 1186.00 1869.00 3055.00 1869.00 3055.00
[1] 40.00 81.05 93.10 12.05 1205.00 1862.00 3067.00
[1] 41.00 80.99 93.21 12.22 1222.00 1856.00 3078.00
[1] 42.00 80.92 93.32 12.40 1240.00 1849.00 3089.00
[1] 43.00 80.86 93.43 12.57 1257.00 1843.00 3100.00
[1] 44.00 80.79 93.54 12.75 1275.00
[1] 45.00 80.73 93.66 12.93 1293.00 1830.00 3123.00
[1] 46.00 80.66 93.77 13.11 1311.00 1823.00 3134.00
[1] 47.00 80.60 93.88 13.28 1328.00 1817.00 3145.00
[1] 48.00 80.53 93.99 13.46 1346.00 1810.00 3156.00
[1] 49.00 80.47 94.10 13.63 1363.00 1804.00 3167.00
[1] 50.00 80.40 94.22 13.82 1382.00 1797.00 3179.00 1797.00 3179.00
[1] 51.00 80.34 94.33 13.99 1399.00 1791.00 3190.00 1791.00 3190.00
[1] 52.00 80.27 94.44 14.17 1417.00 1784.00 3201.00
[1] 53.00 80.20 94.55 14.35 1435.00 1777.00 3212.00
[1] 54.00 80.14 94.66 14.52 1452.00 1771.00 3223.00
[1] 55.00 80.07 94.77 14.70 1470.00 1764.00 3234.00
[1] 56.00 80.01 94.89 14.88 1488.00 1758.00 3246.00
[1] 57.00 79.94 95.00 15.06 1506.00 1751.00 3257.00
[1] 58.00 79.87 95.11 15.24 1524.00 1744.00 3268.00 1744.00 3268.00
[1] 59.00 79.81 95.22 15.41 1541.00 1738.00 3279.00
[1] 60.00 79.74 95.32 15.58 1558.00 1731.00 3289.00
[1] 61.00 79.67 95.43 15.76 1576.00 1724.00 3300.00
[1] 62.00 79.61 95.54 15.93 1593.00 1718.00 3311.00
[1] 63.00 79.54 95.65 16.11 1611.00
[1] 64.00 79.47 95.76 16.29 1629.00 1704.00 3333.00
[1] 65.00 79.41 95.87 16.46 1646.00 1698.00 3344.00
[1] 66.00 79.34 95.97 16.63 1663.00 1691.00 3354.00 1691.00 3354.00
[1] 67.00 79.27 96.08 16.81 1681.00 1684.00 3365.00
[1] 68.00 79.21 96.19 16.98 1698.00 1678.00 3376.00 1678.00 3376.00
[1] 69.00 79.14 96.30 17.16 1716.00 1671.00 3387.00
[1] 70.00 79.07 96.40 17.33 1733.00 1664.00 3397.00
[1] 71.00 79.01 96.51 17.50 1750.00 1658.00 3408.00
as it is obvious there are a lot of numbers for r, where R find nothing
and some in sp1 where r find nothing.
and here some more informations to my curiosity:
> nstu[10,1]
[1] 84.68
> r[2225,1]
[1] 84.68
> is(r)
[1] "matrix" "array" "structure" "vector"
> is(nstu)
[1] "matrix" "array" "structure" "vector"
> nstu[11,1]
[1] 84.38
> r[2195,1]
[1] 84.38
> which(r==nstu[10,1])
[1] 2225
> which(r==nstu[11,1])
integer(0)
why is it like that?
Thanks for a answer
max
More information about the R-help
mailing list