Does anyone understand this? I have a long vector parlist containing values of 138 parameters in 100 simulations. The factor parno is defined by trys <- 100 sim <- gl(trys,138) parno <- gl(138,1,trys*138) I want to extract and compare results for related groups of parameters but I get inconsistent results:> length(parlist[parno==37:42])[1] 600> length(parlist[parno==c(37,38,39,40,41,42)])[1] 600> length(parlist[parno==c(43, 48, 53, 58, 63, 68)])[1] 200 Which I feel should be 600. I am using R1.2.1 under Windows NT 4.0. Murray Jorgensen> tapply(parlist,parno,length)1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 127 128 129 130 131 132 133 134 135 136 137 138 100 100 100 100 100 100 100 100 100 100 100 100 Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html Department of Statistics, University of Waikato, Hamilton, New Zealand Email: maj at waikato.ac.nz Fax +64-7 838 4155 Phone +64-7 838 4773 home phone +64-7 856 6705 Mobile +64-21 139 5862 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Murray Jorgensen <maj at waikato.ac.nz> writes:> Does anyone understand this? > > I have a long vector parlist containing values of 138 parameters in 100 > simulations. > The factor parno is defined by > trys <- 100 > sim <- gl(trys,138) > parno <- gl(138,1,trys*138) > > I want to extract and compare results for related groups of parameters but I > get inconsistent results: > > > length(parlist[parno==37:42]) > [1] 600 > > length(parlist[parno==c(37,38,39,40,41,42)]) > [1] 600 > > length(parlist[parno==c(43, 48, 53, 58, 63, 68)]) > [1] 200 > > Which I feel should be 600.You want %in%, not == there. Beware the effects of vector recycling. Same thing with shorter vectors:> 1:12 == 3:5[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE> 1:12 == 4:6[1] FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE since> cbind(1:12,3:5,4:6)[,1] [,2] [,3] [1,] 1 3 4 [2,] 2 4 5 [3,] 3 5 6 [4,] 4 3 4 [5,] 5 4 5 [6,] 6 5 6 [7,] 7 3 4 [8,] 8 4 5 [9,] 9 5 6 [10,] 10 3 4 [11,] 11 4 5 [12,] 12 5 6 You're effectively only counting those items for which the number matches the position modulo 6:> c(43, 48, 53, 58, 63, 68) %% 6 == 1:6 %% 6[1] TRUE FALSE FALSE TRUE FALSE FALSE> 37:42 %% 6 == 1:6 %% 6[1] TRUE TRUE TRUE TRUE TRUE TRUE -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._