[R] help to extract data with R
Weidong Gu
anopheles123 at gmail.com
Sun Oct 30 23:37:47 CET 2011
One option is to use table to get the number of repeats
tab<-table(tr1$time)==3
time3<-names(tab)[tab]
tr1[tr1$time%in%time3,]
Weidong Gu
On Sun, Oct 30, 2011 at 5:10 PM, Zheng Lu <luyan6 at hotmail.com> wrote:
>
>
>
>
> With the following dataset, trl =1, 2,3, how to extract data with the time repeated 3 times. For example, I am only interested in the data records with time repeated 3 times. time=0.1 only has 1 time, we don't want it, time=0.3 only has two times, we don't want it, and so on. Thanks a lot.
>
> time surv trl
> 1 0.0 0.990 1
> 124 0.0 0.995 2
> 250 0.0 0.980 3
> 125 0.1 0.990 2
> 2 0.2 0.985 1
> 126 0.2 0.985 2
> 251 0.2 0.975 3
> 3 0.3 0.980 1
> 127 0.3 0.980 2
> 4 0.4 0.975 1
> 128 0.4 0.975 2
> 252 0.4 0.965 3
> 5 0.5 0.970 1
> 6 0.6 0.965 1
> 129 0.6 0.970 2
> 253 0.6 0.955 3
> 7 0.8 0.960 1
> 130 0.8 0.960 2
> 254 0.8 0.950 3
> 131 0.9 0.955 2
> 255 0.9 0.945 3
> 8 1.0 0.955 1
> 256 1.0 0.940 3
> time surv trl
> 257 1.3 0.935 3
> 9 1.7 0.950 1
> 132 1.8 0.950 2
> 258 1.8 0.930 3
> 133 1.9 0.945 2
> 259 1.9 0.925 3
> 10 2.0 0.945 1
> 134 2.0 0.935 2
> 260 2.1 0.915 3
> 11 2.2 0.935 1
> 135 2.2 0.930 2
> 261 2.2 0.905 3
> 12 2.4 0.930 1
> 262 2.4 0.900 3
> 13 2.5 0.925 1
> 136 2.5 0.925 2
> 263 2.5 0.895 3
> 137 2.6 0.915 2
> 264 2.6 0.880 3
> 14 2.7 0.915 1
> 138 2.7 0.895 2
> 265 2.7 0.870 3
> 15 2.8 0.910 1
> time surv trl
> 266 2.8 0.860 3
> 16 2.9 0.895 1
> 267 2.9 0.855 3
> 17 3.0 0.890 1
> 139 3.0 0.885 2
> 268 3.0 0.840 3
> 18 3.1 0.885 1
> 269 3.1 0.835 3
> 19 3.2 0.880 1
> 270 3.2 0.830 3
> 20 3.3 0.875 1
> 140 3.3 0.880 2
> 141 3.4 0.870 2
> 21 3.5 0.870 1
> 142 3.8 0.855 2
> 271 3.8 0.825 3
> 22 3.9 0.860 1
> 143 3.9 0.845 2
> 272 3.9 0.820 3
> 273 4.0 0.805 3
> 144 4.1 0.840 2
> 274 4.1 0.800 3
> 145 4.2 0.835 2
> time surv trl
> 275 4.2 0.795 3
> 23 4.3 0.855 1
> 24 4.4 0.850 1
> 146 4.4 0.830 2
> 276 4.4 0.790 3
> 25 4.5 0.835 1
> 147 4.5 0.825 2
> 277 4.5 0.785 3
> 26 4.6 0.820 1
> 278 4.6 0.780 3
> 27 4.7 0.810 1
> 148 4.7 0.820 2
> 28 4.8 0.805 1
> 29 4.9 0.800 1
> 149 4.9 0.815 2
> 279 5.0 0.770 3
> 30 5.1 0.790 1
> 150 5.1 0.805 2
> 31 5.2 0.785 1
> 151 5.2 0.800 2
> 32 5.3 0.780 1
> 152 5.3 0.795 2
> 33 5.4 0.775 1
> time surv trl
> 280 5.4 0.750 3
> 153 5.5 0.790 2
> 34 5.6 0.765 1
> 281 5.7 0.745 3
> 154 5.8 0.775 2
> 155 5.9 0.770 2
> 35 6.0 0.760 1
> 282 6.0 0.740 3
> 283 6.1 0.735 3
> 36 6.2 0.750 1
> 284 6.2 0.725 3
> 285 6.3 0.720 3
> 37 6.4 0.745 1
> 156 6.4 0.765 2
> 157 6.5 0.760 2
> 286 6.5 0.710 3
> 38 6.6 0.735 1
> 158 6.6 0.755 2
> 159 6.7 0.745 2
> 287 6.7 0.700 3
> 288 6.8 0.690 3
> 39 6.9 0.725 1
> 160 6.9 0.735 2
> time surv trl
> 289 6.9 0.685 3
> 40 7.0 0.715 1
> 161 7.0 0.720 2
> 41 7.1 0.710 1
> 162 7.1 0.710 2
> 42 7.2 0.705 1
> 290 7.2 0.670 3
> 43 7.3 0.700 1
> 163 7.3 0.705 2
> 44 7.4 0.690 1
> 164 7.4 0.700 2
> 291 7.4 0.660 3
> 165 7.5 0.690 2
> 292 7.6 0.650 3
> 45 7.7 0.685 1
> 166 7.8 0.685 2
> 46 7.9 0.680 1
> 167 7.9 0.680 2
> 293 7.9 0.645 3
> 47 8.0 0.675 1
> 168 8.0 0.675 2
> 294 8.0 0.640 3
> 48 8.1 0.665 1
> time surv trl
> 295 8.1 0.635 3
> 49 8.4 0.655 1
> 296 8.4 0.625 3
> 169 8.5 0.670 2
> 297 8.5 0.620 3
> 170 8.6 0.665 2
> 50 8.7 0.645 1
> 171 8.7 0.660 2
> 298 8.7 0.615 3
> 172 8.8 0.655 2
> 51 8.9 0.635 1
> 52 9.0 0.630 1
> 53 9.1 0.620 1
> 173 9.1 0.650 2
> 54 9.2 0.610 1
> 174 9.2 0.640 2
> 55 9.3 0.600 1
> 175 9.4 0.635 2
> 299 9.4 0.605 3
> 176 9.5 0.620 2
> 177 9.6 0.610 2
> 300 9.6 0.595 3
> 178 9.7 0.605 2
> time surv trl
> 179 9.8 0.600 2
> 301 9.8 0.590 3
> 56 9.9 0.595 1
> 180 9.9 0.595 2
> 302 9.9 0.585 3
> 303 10.0 0.580 3
> 181 10.1 0.590 2
> 57 10.2 0.590 1
> 304 10.2 0.575 3
> 182 10.4 0.585 2
> 183 10.5 0.570 2
> 184 10.6 0.565 2
> 305 10.6 0.570 3
> 58 10.7 0.580 1
> 185 10.7 0.560 2
> 186 10.8 0.555 2
> 187 11.0 0.545 2
> 188 11.1 0.540 2
> 306 11.1 0.565 3
> 59 11.2 0.575 1
> 189 11.3 0.535 2
> 307 11.3 0.555 3
> 60 11.4 0.560 1
> time surv trl
> 190 11.4 0.530 2
> 308 11.6 0.550 3
> 61 11.7 0.555 1
> 309 11.8 0.545 3
> 62 11.9 0.550 1
> 191 11.9 0.525 2
> 310 11.9 0.540 3
> 63 12.0 0.545 1
> 192 12.0 0.520 2
> 311 12.0 0.535 3
> 193 12.1 0.505 2
> 312 12.2 0.525 3
> 64 12.3 0.540 1
> 194 12.6 0.500 2
> 313 12.6 0.520 3
> 314 12.9 0.515 3
> 195 13.0 0.495 2
> 315 13.2 0.505 3
> 316 13.4 0.500 3
> 65 13.5 0.535 1
> 196 13.5 0.490 2
> 317 13.5 0.495 3
> 66 13.6 0.530 1
> time surv trl
> 197 13.6 0.485 2
> 318 13.6 0.480 3
> 67 13.7 0.525 1
> 198 13.7 0.480 2
> 199 13.8 0.475 2
> 319 13.9 0.475 3
> 68 14.1 0.520 1
> 200 14.1 0.470 2
> 69 14.2 0.515 1
> 201 14.2 0.465 2
> 70 14.5 0.510 1
> 320 14.5 0.470 3
> 321 14.6 0.460 3
> 202 14.8 0.460 2
> 71 15.0 0.505 1
> 72 15.2 0.495 1
> 322 15.4 0.450 3
> 73 15.5 0.490 1
> 203 15.5 0.455 2
> 323 15.5 0.445 3
> 74 15.6 0.485 1
> 204 15.7 0.450 2
> 324 15.7 0.440 3
> time surv trl
> 205 15.8 0.445 2
> 325 15.8 0.435 3
> 75 16.0 0.480 1
> 76 16.1 0.475 1
> 206 16.1 0.440 2
> 77 16.2 0.470 1
> 326 16.2 0.430 3
> 207 16.3 0.435 2
> 327 16.5 0.425 3
> 78 16.6 0.465 1
> 208 16.7 0.430 2
> 328 16.7 0.420 3
> 209 16.8 0.420 2
> 329 16.8 0.415 3
> 330 16.9 0.410 3
> 79 17.0 0.460 1
> 80 17.1 0.455 1
> 210 17.1 0.415 2
> 81 17.2 0.450 1
> 331 17.2 0.405 3
> 82 17.3 0.435 1
> 332 17.3 0.400 3
> 83 17.4 0.430 1
> time surv trl
> 333 17.5 0.390 3
> 334 17.6 0.385 3
> 84 17.7 0.425 1
> 335 17.7 0.380 3
> 211 18.1 0.410 2
> 212 18.2 0.405 2
> 85 18.3 0.420 1
> 213 18.4 0.400 2
> 336 18.4 0.370 3
> 214 18.5 0.395 2
> 86 18.6 0.415 1
> 87 18.9 0.410 1
> 337 18.9 0.365 3
> 338 19.2 0.355 3
> 339 19.3 0.350 3
> 88 19.4 0.405 1
> 340 19.4 0.345 3
> 89 19.5 0.400 1
> 215 19.5 0.390 2
> 216 19.6 0.385 2
> 217 19.7 0.380 2
> 341 19.7 0.340 3
> 90 19.8 0.395 1
> time surv trl
> 91 19.9 0.390 1
> 92 20.0 0.385 1
> 93 20.1 0.380 1
> 218 20.4 0.370 2
> 219 20.5 0.365 2
> 342 20.5 0.330 3
> 220 20.8 0.360 2
> 343 20.9 0.325 3
> 221 21.0 0.355 2
> 344 21.0 0.320 3
> 94 21.1 0.375 1
> 345 21.1 0.315 3
> 222 21.2 0.350 2
> 95 21.5 0.370 1
> 96 21.7 0.365 1
> 97 22.0 0.360 1
> 223 22.0 0.345 2
> 346 22.3 0.310 3
> 224 22.4 0.335 2
> 98 23.0 0.355 1
> 347 23.0 0.305 3
> 348 23.2 0.300 3
> 349 23.4 0.295 3
> time surv trl
> 99 23.5 0.350 1
> 225 23.5 0.330 2
> 226 23.8 0.325 2
> 227 24.0 0.320 2
> 228 24.4 0.315 2
> 100 24.5 0.345 1
> 101 24.7 0.340 1
> 229 24.7 0.310 2
> 230 24.8 0.305 2
> 102 25.1 0.335 1
> 350 25.3 0.290 3
> 231 25.6 0.295 2
> 103 25.7 0.330 1
> 232 25.7 0.290 2
> 351 25.8 0.285 3
> 352 25.9 0.280 3
> 104 26.0 0.325 1
> 233 26.0 0.285 2
> 234 26.2 0.280 2
> 105 26.4 0.320 1
> 106 26.5 0.310 1
> 235 26.6 0.275 2
> 107 26.9 0.305 1
> time surv trl
> 236 27.2 0.270 2
> 353 27.2 0.275 3
> 354 27.3 0.270 3
> 237 27.5 0.265 2
> 355 27.6 0.265 3
> 108 28.0 0.300 1
> 109 28.1 0.295 1
> 110 28.4 0.290 1
> 111 28.6 0.285 1
> 238 28.6 0.260 2
> 112 28.7 0.275 1
> 113 28.9 0.270 1
> 356 29.0 0.260 3
> 239 29.1 0.255 2
> 357 29.5 0.255 3
> 240 29.7 0.245 2
> 114 29.9 0.265 1
> 115 30.2 0.260 1
> 241 30.3 0.240 2
> 242 30.9 0.235 2
> 116 31.4 0.255 1
> 243 31.5 0.230 2
> 117 31.8 0.250 1
> time surv trl
> 118 31.9 0.245 1
> 119 32.5 0.240 1
> 244 32.5 0.225 2
> 358 32.7 0.250 3
> 245 32.8 0.220 2
> 246 33.2 0.215 2
> 359 33.9 0.245 3
> 360 34.3 0.240 3
> 361 34.5 0.235 3
> 247 34.6 0.210 2
> 362 34.8 0.230 3
> 120 35.1 0.235 1
> 248 35.6 0.200 2
> 363 36.0 0.215 3
> 121 36.6 0.230 1
> 122 37.1 0.225 1
> 364 37.2 0.210 3
> 365 37.3 0.205 3
> 249 37.6 0.195 2
> 366 37.8 0.200 3
> 367 38.3 0.195 3
> 368 38.6 0.190 3
> 369 39.5 0.185 3
> time surv trl
> 123 39.7 0.220 1
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list