Equivalent to as.data.frame(table(x)), but does not include combinations with zero counts.

count(df, vars = NULL, wt_var = NULL)

Arguments

df

data frame to be processed

vars

variables to count unique values of

wt_var

optional variable to weight by - if this is non-NULL, count will sum up the value of this variable for each combination of id variables.

Value

a data frame with label and freq columns

Details

Speed-wise count is competitive with table for single variables, but it really comes into its own when summarising multiple dimensions because it only counts combinations that actually occur in the data.

Compared to table + as.data.frame, count also preserves the type of the identifier variables, instead of converting them to characters/factors.

See also

table for related functionality in the base package

Examples

# Count of each value of "id" in the first 100 cases count(baseball[1:100,], vars = "id")
#> id freq #> 1 ansonca01 8 #> 2 bennech01 1 #> 3 burdoja01 7 #> 4 forceda01 9 #> 5 galvipu01 1 #> 6 gerhajo01 5 #> 7 hinespa01 6 #> 8 jonesch01 6 #> 9 mathebo01 7 #> 10 morrijo01 2 #> 11 nelsoca01 5 #> 12 orourji01 6 #> 13 shaffor01 4 #> 14 snydepo01 5 #> 15 startjo01 7 #> 16 suttoez01 7 #> 17 whitede01 7 #> 18 yorkto01 7
# Count of ids, weighted by their "g" loading count(baseball[1:100,], vars = "id", wt_var = "g")
#> id freq #> 1 ansonca01 432 #> 2 bennech01 49 #> 3 burdoja01 414 #> 4 forceda01 380 #> 5 galvipu01 13 #> 6 gerhajo01 209 #> 7 hinespa01 302 #> 8 jonesch01 134 #> 9 mathebo01 327 #> 10 morrijo01 127 #> 11 nelsoca01 193 #> 12 orourji01 356 #> 13 shaffor01 90 #> 14 snydepo01 250 #> 15 startjo01 389 #> 16 suttoez01 344 #> 17 whitede01 386 #> 18 yorkto01 396
count(baseball, "id", "ab")
#> id freq #> 1 aaronha01 12364 #> 2 abernte02 181 #> 3 adairje01 4019 #> 4 adamsba01 1019 #> 5 adamsbo03 4019 #> 6 adcocjo01 6606 #> 7 agostju01 20 #> 8 aguilri01 139 #> 9 aguirha01 388 #> 10 ainsmed01 3048 #> 11 alexado01 265 #> 12 alexape01 1810 #> 13 allendi01 6332 #> 14 allenet01 4418 #> 15 allenjo02 716 #> 16 almonbi01 3330 #> 17 alomaro01 9073 #> 18 alomasa01 4760 #> 19 alomasa02 4530 #> 20 aloufe01 7339 #> 21 alouje01 4345 #> 22 alouma01 5789 #> 23 aloumo01 6988 #> 24 altroni01 550 #> 25 alvarwi01 95 #> 26 amesre01 1014 #> 27 anderbr01 6499 #> 28 anderjo01 6341 #> 29 anderla02 38 #> 30 ansonca01 10277 #> 31 aparilu01 10230 #> 32 appieke01 83 #> 33 applepe01 374 #> 34 applilu01 8856 #> 35 ashburi01 8365 #> 36 ashbyal01 4123 #> 37 ashbyan01 521 #> 38 assenpa01 36 #> 39 astacpe01 676 #> 40 ausmubr01 5905 #> 41 austiji01 5388 #> 42 azcuejo01 2828 #> 43 baergca01 5439 #> 44 bagweje01 7797 #> 45 bahnsst01 479 #> 46 bailebo01 6082 #> 47 baileed01 3581 #> 48 baineha01 9908 #> 49 bairdo01 52 #> 50 bakerdu01 7117 #> 51 bakerfl01 2280 #> 52 bancrda01 7182 #> 53 bandosa01 7060 #> 54 bankser01 9421 #> 55 bannifl01 80 #> 56 barbest01 563 #> 57 barrysh01 4014 #> 58 bartedi01 7629 #> 59 basske01 4839 #> 60 baylodo01 8198 #> 61 becklja01 9526 #> 62 bedrost01 153 #> 63 belanma01 5784 #> 64 belchti01 388 #> 65 bellbu01 8995 #> 66 bellda01 4826 #> 67 bellgu01 6478 #> 68 bellira01 2301 #> 69 bellja01 7398 #> 70 benchjo01 7658 #> 71 bendech01 1147 #> 72 benesan01 741 #> 73 beniqju01 4651 #> 74 benitar01 8 #> 75 bennech01 3821 #> 76 bentola01 738 #> 77 bentoru01 825 #> 78 berenju01 24 #> 79 bergmda01 2679 #> 80 bergmo01 1813 #> 81 berrayo01 7555 #> 82 bevacku01 2117 #> 83 bicheda01 6381 #> 84 bielemi01 282 #> 85 biggicr01 10876 #> 86 biittla01 3151 #> 87 blackbu02 179 #> 88 blairpa01 6042 #> 89 blasido01 5296 #> 90 bluegos01 6440 #> 91 bluevi01 512 #> 92 blylebe01 451 #> 93 boddimi01 0 #> 94 boggswa01 9180 #> 95 bondsba01 9847 #> 96 bondsbo01 7043 #> 97 bonilbo01 7213 #> 98 boonebo01 7245 #> 99 boonebr01 6683 #> 100 boonera01 4589 #> 101 bordepa01 3282 #> 102 bordimi01 5770 #> 103 bosleth01 1581 #> 104 bottoji01 7471 #> 105 boudrlo01 6029 #> 106 bowala01 8418 #> 107 bowerfr01 3401 #> 108 boyercl02 5780 #> 109 boyerke01 7455 #> 110 braunst01 3650 #> 111 bresnro01 4481 #> 112 bressru01 3881 #> 113 brettge01 10349 #> 114 brettke01 347 #> 115 breweji01 140 #> 116 bridgto01 1003 #> 117 brilene01 469 #> 118 brinked01 6045 #> 119 brocklo01 10332 #> 120 brookhu01 5974 #> 121 broutda01 6711 #> 122 browncl01 457 #> 123 brownge01 4300 #> 124 brownha01 484 #> 125 brownke01 495 #> 126 brownmo01 1143 #> 127 brownol02 3642 #> 128 brownpe01 4820 #> 129 brownto01 7363 #> 130 brunato01 6289 #> 131 brunege01 418 #> 132 bucknbi01 9397 #> 133 buhlbo01 857 #> 134 buhneja01 5013 #> 135 bunniji01 1275 #> 136 burbada01 194 #> 137 burdele01 1011 #> 138 burdoja01 4915 #> 139 burgesm01 4471 #> 140 burgmto01 66 #> 141 burkeje01 8421 #> 142 burkejo03 540 #> 143 burksel01 7232 #> 144 burnije01 5710 #> 145 burnsge01 7241 #> 146 burnsge02 6573 #> 147 burrira01 502 #> 148 burroje01 5536 #> 149 busbyji01 4250 #> 150 bushdo01 7210 #> 151 bushgu01 888 #> 152 bushjo01 1239 #> 153 butlebr01 8180 #> 154 byrneto01 601 #> 155 cabelen01 5952 #> 156 caldwmi01 216 #> 157 callijo01 6652 #> 158 caminke01 6288 #> 159 campabe01 8684 #> 160 campbbi02 26 #> 161 candejo01 596 #> 162 candito01 299 #> 163 cansejo01 7057 #> 164 carbobe01 2733 #> 165 cardejo02 6964 #> 166 cardele01 6707 #> 167 cardwdo01 698 #> 168 carewro01 9315 #> 169 careyma01 9363 #> 170 carlsha01 712 #> 171 carltst01 1719 #> 172 carrocl02 208 #> 173 cartega01 7971 #> 174 cartejo01 8422 #> 175 cartyri01 5606 #> 176 cashno01 6705 #> 177 castivi02 6822 #> 178 cavarph01 6754 #> 179 cedence01 7310 #> 180 cepedor01 7927 #> 181 ceronri01 4069 #> 182 cervbo01 2261 #> 183 ceyro01 7162 #> 184 chambch01 7571 #> 185 chancfr01 4297 #> 186 chapmbe01 6478 #> 187 charlno01 87 #> 188 chaseha01 7417 #> 189 cicoted01 1062 #> 190 cirilje01 5396 #> 191 clancji01 61 #> 192 clarkfr01 8568 #> 193 clarkja01 6847 #> 194 clarkwi02 7173 #> 195 claytro01 7379 #> 196 clemeja01 4283 #> 197 clemero01 9454 #> 198 clemero02 179 #> 199 clinety01 1834 #> 200 cobbty01 11434 #> 201 coffmdi01 400 #> 202 colavro01 6503 #> 203 colbrgr01 2769 #> 204 colemjo05 462 #> 205 colesda01 2891 #> 206 collida02 4907 #> 207 collied01 9949 #> 208 colliji01 6795 #> 209 collish01 6390 #> 210 conceda01 8723 #> 211 coneda01 412 #> 212 coninje01 6957 #> 213 connoro01 7794 #> 214 cookde01 110 #> 215 coonejo01 3372 #> 216 coopece01 7349 #> 217 coopewa01 4702 #> 218 coopewi01 1227 #> 219 corcoto01 8804 #> 220 cordewi01 4311 #> 221 cormirh01 192 #> 222 covinwe01 2978 #> 223 cramedo01 9140 #> 224 crandde01 5026 #> 225 crawfsa01 9570 #> 226 crawfwi01 3435 #> 227 crigelo01 3202 #> 228 cronijo01 7579 #> 229 crosefr01 6277 #> 230 crossla01 9072 #> 231 crossmo01 5821 #> 232 crowlte01 1518 #> 233 cruzjo01 7917 #> 234 cuccito01 6184 #> 235 cuellmi01 661 #> 236 curtijo01 359 #> 237 cuyleki01 7161 #> 238 dahlebi01 9031 #> 239 dahlgba01 4045 #> 240 dalyto01 5684 #> 241 darkal01 7219 #> 242 darliro01 526 #> 243 darwida01 305 #> 244 daubeja01 7673 #> 245 daultda01 3630 #> 246 daussho01 1124 #> 247 davalvi01 4017 #> 248 davisch01 8673 #> 249 daviscu01 813 #> 250 daviser01 5321 #> 251 davisge01 9031 #> 252 davisha01 6653 #> 253 davisma01 167 #> 254 davissp01 4255 #> 255 davisst02 16 #> 256 davisto02 7223 #> 257 daviswi02 9174 #> 258 dawsoan01 9927 #> 259 decindo01 5809 #> 260 dejesiv01 4602 #> 261 delahed01 7505 #> 262 delahji01 4091 #> 263 deleojo01 419 #> 264 delgaca01 6591 #> 265 dempsri01 4692 #> 266 dennyje01 4946 #> 267 derripa01 1260 #> 268 dickebi01 6300 #> 269 dicksmu01 1095 #> 270 dietrbi01 627 #> 271 dilonmi01 2000 #> 272 doakbi01 905 #> 273 donovbi01 1302 #> 274 donovdi01 694 #> 275 donovpa01 7496 #> 276 dooinre01 4004 #> 277 doolami01 5977 #> 278 downial01 717 #> 279 downibr01 7853 #> 280 doyleja01 6039 #> 281 doylela01 6509 #> 282 drabomo01 420 #> 283 driesda01 5479 #> 284 dropowa01 4124 #> 285 duceyro01 1279 #> 286 duffyhu01 7042 #> 287 duganjo01 5410 #> 288 duncama01 4677 #> 289 dunstsh01 5927 #> 290 durocle01 5350 #> 291 dwyerji01 2761 #> 292 dykesji01 8046 #> 293 easleda01 5168 #> 294 easlemi01 3677 #> 295 eckerde01 181 #> 296 edmonji01 6272 #> 297 ehmkeho01 1009 #> 298 eisenji01 3995 #> 299 elberki01 4561 #> 300 elliobo01 7141 #> 301 ellisdo01 489 #> 302 ellswdi01 673 #> 303 elybo01 5159 #> 304 embreal01 3 #> 305 ennisde01 7254 #> 306 ericksc01 35 #> 307 etchean01 2618 #> 308 evansda01 8973 #> 309 evansdw01 8996 #> 310 evereca01 4809 #> 311 eversho01 3801 #> 312 eversjo01 6137 #> 313 ewingbu01 5363 #> 314 faberre01 1269 #> 315 facero01 194 #> 316 fairlro01 7184 #> 317 farredu01 5679 #> 318 farretu01 436 #> 319 fasseje01 276 #> 320 fellebo01 1282 #> 321 fergujo01 3001 #> 322 fernasi01 539 #> 323 fernato01 7911 #> 324 ferreri01 6028 #> 325 ferrewe01 1176 #> 326 fettemi01 0 #> 327 fieldce01 5157 #> 328 fingero01 180 #> 329 finlech01 53 #> 330 finlest01 9397 #> 331 finnelo01 4631 #> 332 fisheed02 246 #> 333 fiskca01 8756 #> 334 fitzsfr01 1155 #> 335 flagsir01 4139 #> 336 flahejo01 3372 #> 337 flanami01 0 #> 338 fletcda01 3902 #> 339 fletcsc01 5258 #> 340 floodcu01 6357 #> 341 floydcl01 5057 #> 342 foileha01 1455 #> 343 foleyto02 2708 #> 344 foliti01 6047 #> 345 forceda01 4251 #> 346 fordho01 4833 #> 347 fordwh01 1023 #> 348 foremfr01 754 #> 349 fornimi01 308 #> 350 forscbo01 893 #> 351 forscke01 383 #> 352 forstte01 78 #> 353 fostege01 7023 #> 354 fournja01 5208 #> 355 foxne01 9232 #> 356 foxxji01 8134 #> 357 francjo01 34 #> 358 francju01 8677 #> 359 francti01 5121 #> 360 frasech01 1316 #> 361 freehbi01 6073 #> 362 freesge02 3446 #> 363 fregoji01 6523 #> 364 frencla01 1057 #> 365 freylo01 5517 #> 366 fribebe01 4169 #> 367 frienbo01 1137 #> 368 friscfr01 9112 #> 369 frymawo01 609 #> 370 furilca01 6378 #> 371 gaettga01 8951 #> 372 gagnegr01 5673 #> 373 galanau01 5937 #> 374 galaran01 8096 #> 375 galehde01 665 #> 376 galvipu01 2748 #> 377 gamblos01 4502 #> 378 gantnji01 6189 #> 379 gantro01 6449 #> 380 ganzech01 2984 #> 381 garbege01 115 #> 382 gardnla01 6688 #> 383 garneph01 6136 #> 384 garvene01 827 #> 385 garvest01 8835 #> 386 gehrich01 8860 #> 387 gehrilo01 8001 #> 388 gerbewa01 5099 #> 389 gerhajo01 4139 #> 390 geronce01 3780 #> 391 gibbojo01 263 #> 392 gibsobo01 1328 #> 393 gibsoki01 5798 #> 394 ginsbjo01 1716 #> 395 girarjo01 4127 #> 396 giustda01 412 #> 397 glassja01 7030 #> 398 glavito02 1304 #> 399 gleaski01 7452 #> 400 gomezch02 4421 #> 401 gonzaal01 4977 #> 402 gonzaju03 6556 #> 403 gonzalu01 8816 #> 404 gonzami01 2829 #> 405 gonzato01 5195 #> 406 goodedw01 741 #> 407 goodmbi01 5644 #> 408 goodwto01 3846 #> 409 gordoto01 2 #> 410 gorege01 5357 #> 411 gosligo01 8656 #> 412 gossari01 85 #> 413 gottji01 73 #> 414 gowdyha01 2735 #> 415 gracema01 8065 #> 416 graffto01 2787 #> 417 grantmu01 759 #> 418 greenle01 2956 #> 419 greensh01 7082 #> 420 grichbo01 6890 #> 421 griffal01 6780 #> 422 griffcl01 1380 #> 423 griffke01 7229 #> 424 griffke02 8826 #> 425 griffto02 405 #> 426 grimebu01 1535 #> 427 grimmch01 7917 #> 428 grimsja01 43 #> 429 grissma02 8275 #> 430 groatdi01 7484 #> 431 grohhe01 6074 #> 432 gromest01 630 #> 433 groombu01 0 #> 434 grossgr01 3745 #> 435 grosske01 660 #> 436 groteje01 4339 #> 437 grothjo01 3808 #> 438 grovele01 1369 #> 439 grubbjo01 4154 #> 440 guarded01 1 #> 441 guerrpe01 5392 #> 442 guilloz01 6686 #> 443 gullibi01 576 #> 444 gumbeha01 708 #> 445 gurala01 33 #> 446 guthrma01 14 #> 447 gwynnto01 9288 #> 448 hackst01 7278 #> 449 haddiha01 798 #> 450 hadlebu01 1004 #> 451 haineje01 1124 #> 452 hairsje01 1699 #> 453 halldi01 714 #> 454 hallmbi01 6012 #> 455 hamilda02 4577 #> 456 hamilea01 733 #> 457 hammoje01 3032 #> 458 hamnegr01 5839 #> 459 hanseda01 1793 #> 460 hansero02 4311 #> 461 hardeme01 1203 #> 462 harnipe01 513 #> 463 harpebr01 3151 #> 464 harpeto01 6269 #> 465 harrato01 7402 #> 466 harrebu01 4744 #> 467 harrigr01 68 #> 468 harrile01 3924 #> 469 hartnga01 6432 #> 470 hassero01 3440 #> 471 hasslan01 29 #> 472 hatchbi01 4339 #> 473 hattogr01 4206 #> 474 hayesch01 5262 #> 475 hayesfr01 4493 #> 476 haywora01 2062 #> 477 heathcl01 4443 #> 478 heathje01 4937 #> 479 heathmi02 4212 #> 480 hebneri01 6144 #> 481 heganji01 4772 #> 482 heganmi01 2080 #> 483 heilmha01 7787 #> 484 heldwo01 4019 #> 485 helliri01 104 #> 486 helmsto01 4997 #> 487 hemslro01 5047 #> 488 hendeda01 5130 #> 489 hendeke01 4553 #> 490 henderi01 10961 #> 491 hendrge01 7129 #> 492 henrybi01 203 #> 493 herbera01 569 #> 494 hermabi01 7707 #> 495 hernajo01 4618 #> 496 hernake01 7370 #> 497 hernaro01 2 #> 498 herrto01 5349 #> 499 hershor01 810 #> 500 herzobu01 5284 #> 501 hickmch01 3982 #> 502 higbeki01 660 #> 503 higgipi01 6636 #> 504 hillejo01 101 #> 505 hillgl01 3715 #> 506 hillke01 333 #> 507 hillma01 1809 #> 508 hinespa01 7062 #> 509 hitchst01 210 #> 510 hoagmy01 3147 #> 511 hodgegi01 7030 #> 512 hoeftbi01 531 #> 513 hoernjo01 59 #> 514 hoffmtr01 33 #> 515 hofmaso01 4072 #> 516 hollato01 3191 #> 517 holmeda01 28 #> 518 holtzke01 607 #> 519 honeyri01 182 #> 520 hoopeha01 8785 #> 521 hootobu01 748 #> 522 hoppjo01 4260 #> 523 hornsro01 8173 #> 524 hortowi01 7298 #> 525 houghch01 226 #> 526 howarel01 5363 #> 527 howarfr01 6488 #> 528 howelja01 9 #> 529 hoytwa01 1287 #> 530 hubbeca01 1288 #> 531 hudliwi01 894 #> 532 hugheto01 958 #> 533 hunteca01 658 #> 534 hurstbr01 274 #> 535 incavpe01 4233 #> 536 jacksda02 428 #> 537 jacksda03 2629 #> 538 jacksgr01 236 #> 539 jacksla01 1089 #> 540 jacksmi02 28 #> 541 jacksre01 9864 #> 542 jackstr01 6086 #> 543 jacobba01 5507 #> 544 jamiech01 6560 #> 545 jarvike01 188 #> 546 javiest01 5047 #> 547 jeffegr01 5520 #> 548 jenkife01 896 #> 549 jennihu01 4904 #> 550 johnscl01 3945 #> 551 johnsde01 5941 #> 552 johnsja01 4703 #> 553 johnske02 534 #> 554 johnsla03 5379 #> 555 johnsra05 549 #> 556 johnssi01 709 #> 557 johnssy01 702 #> 558 johnswa01 2324 #> 559 johnto01 900 #> 560 jonesch01 3738 #> 561 jonesda01 3774 #> 562 jonesdo01 7 #> 563 jonesfi01 6747 #> 564 jonessa01 1243 #> 565 jonesto02 19 #> 566 joneswi01 5826 #> 567 joosted01 5606 #> 568 jordabr01 5160 #> 569 jorgemi01 3421 #> 570 joynewa01 7127 #> 571 judgejo01 7898 #> 572 jurgebi01 6253 #> 573 justida01 5625 #> 574 kaatji01 1251 #> 575 kalinal01 10116 #> 576 keefeti01 2083 #> 577 keelewi01 8591 #> 578 kellejo01 7006 #> 579 kellge01 6702 #> 580 kellyge01 5993 #> 581 kellyki01 5894 #> 582 kellypa01 4338 #> 583 kellyro01 4797 #> 584 kennebo01 4624 #> 585 kenneve01 743 #> 586 kentje01 8058 #> 587 kernji01 9 #> 588 kessido01 7651 #> 589 keyji01 2 #> 590 killeha01 8147 #> 591 kingmda01 6677 #> 592 kirkped01 3467 #> 593 kisonbr01 404 #> 594 kittrma01 4027 #> 595 kleinch01 6486 #> 596 kleskry01 5611 #> 597 klinero01 491 #> 598 klippjo01 502 #> 599 kluszte01 5929 #> 600 kneppbo01 840 #> 601 knowlda01 125 #> 602 koneted01 7649 #> 603 koosmje01 915 #> 604 kraneed01 5436 #> 605 kressre01 5087 #> 606 kreutch01 2505 #> 607 kruegbi01 15 #> 608 kuennha01 6913 #> 609 kuheljo01 7984 #> 610 kuzavbo01 256 #> 611 labincl01 227 #> 612 lacyle01 4549 #> 613 lajoina01 9589 #> 614 lampde01 201 #> 615 landrho01 1929 #> 616 langsma01 92 #> 617 laniema01 535 #> 618 lankfra01 5747 #> 619 lansfca01 7158 #> 620 lapoida01 251 #> 621 larkiba01 7937 #> 622 larocda01 61 #> 623 larsedo01 596 #> 624 laryfr01 734 #> 625 laryly01 4603 #> 626 lathaar01 6822 #> 627 lauch01 1170 #> 628 lawtoma02 4763 #> 629 lawve01 883 #> 630 lazzeto01 6297 #> 631 leachto01 7959 #> 632 learyti01 163 #> 633 leebi02 980 #> 634 leeth01 835 #> 635 leibone01 4167 #> 636 leiteal01 530 #> 637 lemonbo01 1183 #> 638 lemonch01 6868 #> 639 leonadu02 1054 #> 640 leonaje01 5045 #> 641 lewisda01 4081 #> 642 leyriji01 2527 #> 643 lindbpa01 133 #> 644 loaizes01 265 #> 645 lockmwh01 5940 #> 646 loftoke01 8120 #> 647 lolicmi01 821 #> 648 lollash01 5351 #> 649 lombaer01 5855 #> 650 lonboji01 770 #> 651 longhe01 7674 #> 652 lopesda01 6354 #> 653 lopezal01 5916 #> 654 lopezja01 5319 #> 655 lowebo01 7064 #> 656 lowenjo01 3476 #> 657 lowrepe01 4317 #> 658 lucasre01 1439 #> 659 lummi01 3554 #> 660 luquedo01 1043 #> 661 luzingr01 6505 #> 662 lylesp01 78 #> 663 lynnfr01 6925 #> 664 lyonste01 1563 #> 665 mabryjo01 3409 #> 666 macfada01 910 #> 667 maddoga01 6331 #> 668 maddugr01 1536 #> 669 maddumi01 92 #> 670 madlobi01 6594 #> 671 magadda01 4159 #> 672 mageesh01 7441 #> 673 majesha01 3421 #> 674 maldoca01 4106 #> 675 mancugu01 4505 #> 676 mannle01 4716 #> 677 mantlmi01 8102 #> 678 manushe01 7654 #> 679 maranra01 10078 #> 680 marbefi01 668 #> 681 maricju01 1221 #> 682 marquru01 1107 #> 683 marshmi01 179 #> 684 martibu01 2743 #> 685 martida01 5795 #> 686 martide01 520 #> 687 martied01 7213 #> 688 martipe02 381 #> 689 martiti01 0 #> 690 martiti02 7111 #> 691 masiph01 3468 #> 692 mastewa02 486 #> 693 mathebo01 2487 #> 694 mathech01 1684 #> 695 matheed01 8537 #> 696 matthga01 7147 #> 697 maulal01 1376 #> 698 maxvida01 3443 #> 699 maxwech01 3245 #> 700 maybejo01 5447 #> 701 mayele01 4048 #> 702 mayle01 7609 #> 703 maymi01 3693 #> 704 maynebr01 3614 #> 705 mayru01 341 #> 706 maysca01 1085 #> 707 mayswi01 10881 #> 708 mazerbi01 7755 #> 709 mazzile01 4124 #> 710 mcauldi01 6185 #> 711 mcbrige01 5526 #> 712 mccarti01 5529 #> 713 mcclubo01 9 #> 714 mccormi03 738 #> 715 mccovwi01 8197 #> 716 mcculcl01 3121 #> 717 mcdanli01 378 #> 718 mcdowsa01 774 #> 719 mcelrch01 42 #> 720 mcfared01 3007 #> 721 mcgeewi01 7649 #> 722 mcgrajo01 3924 #> 723 mcgratu01 214 #> 724 mcgrifr01 8757 #> 725 mcguide01 6290 #> 726 mcgwima01 6187 #> 727 mcinnst01 7822 #> 728 mclemma01 6192 #> 729 mclisca01 490 #> 730 mcmahdo02 168 #> 731 mcmanma01 6660 #> 732 mcmilro01 6752 #> 733 mcmulke01 5131 #> 734 mcnaier01 4519 #> 735 mcphebi01 8291 #> 736 mcraeha01 7218 #> 737 mcwilla01 446 #> 738 meadole01 1117 #> 739 medwijo01 7635 #> 740 merceor01 3998 #> 741 merckke01 248 #> 742 merklfr01 5782 #> 743 mesajo01 2 #> 744 micelda01 22 #> 745 michaca01 4367 #> 746 miksied01 3053 #> 747 milancl01 7359 #> 748 millebi02 6212 #> 749 millebo04 299 #> 750 milleri01 3887 #> 751 millest01 369 #> 752 minchdo01 4026 #> 753 minosmi01 6579 #> 754 mintogr01 103 #> 755 mitchcl01 1287 #> 756 mitchke01 4134 #> 757 mizejo01 6443 #> 758 mogrige01 754 #> 759 molitpa01 10835 #> 760 mondari01 6136 #> 761 mondera01 5814 #> 762 moneydo01 6215 #> 763 montawi01 5843 #> 764 moorech02 4033 #> 765 mooreea01 949 #> 766 moorege03 3543 #> 767 moralje01 4528 #> 768 morgajo02 9277 #> 769 morgami01 497 #> 770 morrija02 1 #> 771 morriji01 3375 #> 772 morrijo01 4912 #> 773 moseswa01 7356 #> 774 mossle01 2234 #> 775 motama01 3779 #> 776 moyerja01 268 #> 777 muellra01 2911 #> 778 mulhote01 619 #> 779 mullato01 2720 #> 780 mullige01 1531 #> 781 mullira01 3569 #> 782 mumphje01 4993 #> 783 murcebo01 6730 #> 784 murphda02 5399 #> 785 murphda05 7960 #> 786 murphto02 289 #> 787 murrada01 65 #> 788 murraed02 11336 #> 789 musiast01 10972 #> 790 mussimi01 47 #> 791 myattgl01 2678 #> 792 myerbu01 7038 #> 793 myersgr01 3042 #> 794 myershy01 4910 #> 795 myersmi01 2 #> 796 myersra01 60 #> 797 nashbi01 5849 #> 798 neaglde01 531 #> 799 nehfar01 915 #> 800 nelsoca01 3294 #> 801 nelsoje01 2 #> 802 nettlgr01 8986 #> 803 nevinph01 4188 #> 804 newhoha01 999 #> 805 newsobo01 1337 #> 806 nichobi01 5546 #> 807 nichoki01 2086 #> 808 niekrjo01 973 #> 809 niekrph01 1537 #> 810 niemabo01 3452 #> 811 nixonot01 5115 #> 812 norenir01 3119 #> 813 normafr01 574 #> 814 northro01 3172 #> 815 nunezed01 0 #> 816 nuxhajo01 766 #> 817 oberkke01 4874 #> 818 obriech01 2232 #> 819 oconnja01 5380 #> 820 odombl01 405 #> 821 oeschjo01 599 #> 822 ofarrbo01 4101 #> 823 offerjo01 5681 #> 824 oglivbe01 5913 #> 825 ojedabo01 347 #> 826 olerujo01 7592 #> 827 olivaom01 242 #> 828 olivato01 6301 #> 829 oliveal01 9049 #> 830 oliveda02 217 #> 831 olivejo01 3367 #> 832 olsongr01 4 #> 833 olsoniv01 6111 #> 834 oneilpa01 7318 #> 835 oneilst01 4795 #> 836 oroscje01 59 #> 837 orourji01 8505 #> 838 ortajo01 5829 #> 839 orthal01 1698 #> 840 osteecl01 1099 #> 841 osterfr01 749 #> 842 otisam01 7299 #> 843 ottme01 9456 #> 844 pacioto01 4121 #> 845 pafkoan01 6292 #> 846 paganjo01 3689 #> 847 palmede01 4902 #> 848 palmeji01 489 #> 849 palmera01 10472 #> 850 pappami01 1073 #> 851 parenma01 1303 #> 852 parkch01 406 #> 853 parkeda01 9358 #> 854 parrila01 6792 #> 855 parrila02 7067 #> 856 pascuca02 967 #> 857 paskedo01 6017 #> 858 peckiro01 7233 #> 859 peitzhe01 4121 #> 860 penaal01 181 #> 861 penaor01 264 #> 862 penato01 6489 #> 863 pendlte01 7032 #> 864 pennohe01 1214 #> 865 perezne01 5127 #> 866 perezto01 9778 #> 867 perkicy01 3604 #> 868 perraro01 167 #> 869 perryga01 1076 #> 870 perryji01 889 #> 871 petryda01 5 #> 872 pfefffr01 6555 #> 873 pfeffje01 874 #> 874 phillda01 6296 #> 875 phillto02 7617 #> 876 piazzmi01 6911 #> 877 picinva01 2877 #> 878 piercbi02 1102 #> 879 piersji01 5890 #> 880 pinielo01 5867 #> 881 pinsova01 9645 #> 882 pippwa01 6914 #> 883 pizarju01 658 #> 884 planked01 1607 #> 885 plesada01 15 #> 886 plunker01 2 #> 887 podrejo01 762 #> 888 polleho01 698 #> 889 polonlu01 4840 #> 890 pooleji02 8 #> 891 portebo01 516 #> 892 porteda02 5539 #> 893 portuma01 450 #> 894 postwa01 4007 #> 895 pottene01 562 #> 896 powelbo01 6681 #> 897 powelja01 1610 #> 898 powerte01 157 #> 899 powervi01 6046 #> 900 prattto02 1612 #> 901 princto01 1190 #> 902 puhlte01 4855 #> 903 purcebl01 4563 #> 904 quantpa01 67 #> 905 quinnja01 1349 #> 906 quinnjo02 6879 #> 907 quirkja01 2266 #> 908 raffeke01 688 #> 909 raganpa01 544 #> 910 raineti01 8872 #> 911 ramirma02 7058 #> 912 ramospe01 703 #> 913 randowi01 8018 #> 914 rasmude01 259 #> 915 rawlijo01 3719 #> 916 readyra01 2110 #> 917 reardje01 57 #> 918 reedje02 3101 #> 919 reedri01 297 #> 920 reedro01 620 #> 921 reedst01 25 #> 922 reesepe01 8058 #> 923 reganph01 321 #> 924 remlimi01 110 #> 925 renkost01 531 #> 926 reuscri01 1115 #> 927 reussje01 1024 #> 928 reynocr01 4466 #> 929 rhodear01 4 #> 930 rhoderi01 761 #> 931 ricede01 3826 #> 932 riceji01 8225 #> 933 ricesa01 9269 #> 934 richaha01 5642 #> 935 richepe01 297 #> 936 righeda01 11 #> 937 ripkeca01 11551 #> 938 rivermi01 5629 #> 939 rixeyep01 1522 #> 940 roberda05 531 #> 941 roberro01 1525 #> 942 robinbi02 4364 #> 943 robinbr01 10654 #> 944 robindo01 631 #> 945 robined01 4282 #> 946 robinfr02 10006 #> 947 robinwi01 5075 #> 948 rodriau01 6611 #> 949 rodriiv01 8247 #> 950 rogerke01 65 #> 951 rojasco01 6309 #> 952 roofph01 2151 #> 953 rootch01 1086 #> 954 rosepe01 14053 #> 955 roushed01 7363 #> 956 rowesc01 909 #> 957 roystje01 4208 #> 958 rudijo01 5556 #> 959 ruelmu01 4514 #> 960 ruffire01 1937 #> 961 russebi01 7318 #> 962 russeja01 617 #> 963 russeje01 79 #> 964 ruthba01 8398 #> 965 ruthvdi01 671 #> 966 ryanji01 8164 #> 967 ryanno01 852 #> 968 saberbr01 190 #> 969 sadecra01 789 #> 970 sallesl01 924 #> 971 samueju01 6081 #> 972 sanchre01 4850 #> 973 sandbry01 8385 #> 974 sandere02 6241 #> 975 sandesc01 474 #> 976 santibe01 6951 #> 977 santoro01 8143 #> 978 sauerha01 4796 #> 979 schaege01 3784 #> 980 schalra01 5306 #> 981 schanwa01 5307 #> 982 schatda01 242 #> 983 schilcu01 773 #> 984 schmija01 591 #> 985 schmijo01 587 #> 986 schmimi01 8352 #> 987 schoere01 8479 #> 988 schofdi01 3083 #> 989 schofdi02 4299 #> 990 schreos01 3057 #> 991 schulfr01 6533 #> 992 scottev01 5837 #> 993 scottge02 7433 #> 994 seaneru01 5 #> 995 seaveto01 1315 #> 996 seguida01 4847 #> 997 seguidi01 384 #> 998 seleaa01 58 #> 999 seminan01 3921 #> 1000 servisc01 17 #> 1001 severha01 4312 #> 1002 sewellu01 5383 #> 1003 seymocy01 5682 #> 1004 shaffor01 3552 #> 1005 shantbo01 548 #> 1006 shawbo01 519 #> 1007 shawkbo01 1049 #> 1008 sheckji01 7605 #> 1009 sheffga01 8531 #> 1010 sherdbi01 960 #> 1011 shortch02 697 #> 1012 shouncl01 362 #> 1013 siebeso01 660 #> 1014 sierrru01 8044 #> 1015 sievero01 6387 #> 1016 simmoal01 8759 #> 1017 simmocu01 1135 #> 1018 simmote01 8680 #> 1019 singebi01 413 #> 1020 singlke01 7189 #> 1021 sislege01 8267 #> 1022 skowrbi01 5547 #> 1023 slatoji01 57 #> 1024 slaugdo01 4063 #> 1025 slaugen01 7946 #> 1026 smallro02 5657 #> 1027 smithbo02 1689 #> 1028 smithea02 2264 #> 1029 smithel01 4684 #> 1030 smithge01 6552 #> 1031 smithja03 4532 #> 1032 smithle02 64 #> 1033 smithlo01 5170 #> 1034 smithoz01 9396 #> 1035 smithpo01 4238 #> 1036 smithre06 7033 #> 1037 smithsh01 709 #> 1038 smithza01 551 #> 1039 smoltjo01 925 #> 1040 snidedu01 7161 #> 1041 snowjt01 5641 #> 1042 snydefr01 4229 #> 1043 snydepo01 3644 #> 1044 sojolu01 2571 #> 1045 sosasa01 8813 #> 1046 spahnwa01 1872 #> 1047 speaktr01 10195 #> 1048 speiech01 7156 #> 1049 spencji01 4908 #> 1050 spilmha01 810 #> 1051 splitpa01 121 #> 1052 sprinru01 27 #> 1053 staintu01 2261 #> 1054 stairma01 4600 #> 1055 stalege01 525 #> 1056 stanlfr01 1650 #> 1057 stanlmi01 5022 #> 1058 stanlmi02 4222 #> 1059 stantmi02 24 #> 1060 stargwi01 7927 #> 1061 startjo01 4747 #> 1062 staubru01 9720 #> 1063 stengca01 4288 #> 1064 stephve01 6497 #> 1065 stewada01 51 #> 1066 stiebda01 2 #> 1067 stinnke01 2033 #> 1068 stobbch01 578 #> 1069 stottto01 242 #> 1070 stoveha01 6138 #> 1071 strawda01 5418 #> 1072 strunam01 4999 #> 1073 sturdto01 328 #> 1074 sullibi03 3647 #> 1075 sundbji01 6021 #> 1076 suppaje01 312 #> 1077 surhobj01 8258 #> 1078 sutclri01 562 #> 1079 suttodo01 1354 #> 1080 suttoez01 5359 #> 1081 sweenma01 1738 #> 1082 swiftbo01 2750 #> 1083 swindgr01 245 #> 1084 tananfr01 59 #> 1085 tanneje01 1410 #> 1086 tapanke01 261 #> 1087 tartada01 5011 #> 1088 tavarju01 139 #> 1089 tayloto02 7680 #> 1090 tayloza02 2865 #> 1091 tebbebi01 3704 #> 1092 tekulke01 121 #> 1093 templga01 7721 #> 1094 tenacge01 4390 #> 1095 tennefr02 7595 #> 1096 terryad01 2389 #> 1097 terryra01 593 #> 1098 theveto01 4164 #> 1099 thomade01 4677 #> 1100 thomafr03 6285 #> 1101 thomafr04 7953 #> 1102 thomage01 1688 #> 1103 thomago01 4677 #> 1104 thomato02 722 #> 1105 thomeji01 6841 #> 1106 thompmi02 3761 #> 1107 thompsa01 5984 #> 1108 thomsbo01 6305 #> 1109 thondi01 4449 #> 1110 thornan01 5291 #> 1111 tiantlu01 513 #> 1112 tidrodi01 95 #> 1113 timlimi01 7 #> 1114 tinkejo01 6434 #> 1115 torgeea01 4969 #> 1116 torrejo01 7874 #> 1117 torremi01 412 #> 1118 trachst01 651 #> 1119 trammal01 8288 #> 1120 traynpi01 7559 #> 1121 trevial01 2430 #> 1122 trillma01 5950 #> 1123 troutdi01 961 #> 1124 truckvi01 949 #> 1125 tucketo01 6479 #> 1126 turnete01 5921 #> 1127 uhlege01 1360 #> 1128 unserde01 5215 #> 1129 valdeis01 399 #> 1130 valenfe01 936 #> 1131 valenjo03 5539 #> 1132 valoel01 5029 #> 1133 vanceda01 971 #> 1134 vandejo02 2751 #> 1135 vanhage01 8021 #> 1136 vaughgr01 6103 #> 1137 veachbo01 6656 #> 1138 velarra01 4244 #> 1139 venturo01 7064 #> 1140 vernomi01 8731 #> 1141 villoro01 169 #> 1142 violafr01 185 #> 1143 vizcajo01 5379 #> 1144 vizquom01 9479 #> 1145 wagneha01 1849 #> 1146 wagneho01 10430 #> 1147 wakefti01 98 #> 1148 walberu01 905 #> 1149 walkedi02 6740 #> 1150 walkege02 6771 #> 1151 walkela01 6907 #> 1152 walketo04 4554 #> 1153 wallabo01 8618 #> 1154 wallati01 8099 #> 1155 wallide01 2945 #> 1156 waltebu01 1966 #> 1157 wanerll01 7772 #> 1158 wanerpa01 9459 #> 1159 wardjo01 7647 #> 1160 warnejo01 3494 #> 1161 warnelo01 962 #> 1162 washicl01 6787 #> 1163 watsobo01 6185 #> 1164 weathda01 139 #> 1165 webstmi01 3419 #> 1166 wehmehe01 633 #> 1167 welchbo01 582 #> 1168 wellsda01 178 #> 1169 wertzvi01 6099 #> 1170 westsa01 6148 #> 1171 weyhigu01 1849 #> 1172 wheatza01 9106 #> 1173 whitalo01 8570 #> 1174 whitede01 6624 #> 1175 whitede03 7344 #> 1176 whiteea01 1291 #> 1177 whitefr01 7859 #> 1178 whitema01 3104 #> 1179 whiteri01 43 #> 1180 whitero01 6650 #> 1181 whitero02 5357 #> 1182 whitsed01 576 #> 1183 whitter01 3774 #> 1184 wickmbo01 2 #> 1185 wightbi01 480 #> 1186 wilcomi01 62 #> 1187 wilheho01 432 #> 1188 wilkiri01 2114 #> 1189 willibe02 7869 #> 1190 willibi01 9350 #> 1191 willicy01 6780 #> 1192 willidi02 2959 #> 1193 willige02 3059 #> 1194 willima04 7000 #> 1195 willist02 502 #> 1196 willite01 7706 #> 1197 williwo02 540 #> 1198 willsma01 7588 #> 1199 wilsoar01 2056 #> 1200 wilsoji01 4778 #> 1201 wilsowi02 7731 #> 1202 winfida01 11003 #> 1203 wingoiv01 4003 #> 1204 wiseri01 668 #> 1205 witasja01 42 #> 1206 wittbo01 64 #> 1207 wohlfji01 3049 #> 1208 womacto01 4963 #> 1209 woodge01 5371 #> 1210 woodlge01 5587 #> 1211 woodwi01 322 #> 1212 worreti01 81 #> 1213 worthal01 255 #> 1214 wyattwh01 607 #> 1215 wynnea01 1704 #> 1216 wynnji01 6653 #> 1217 yastrca01 11988 #> 1218 yeagest01 3584 #> 1219 yorkto01 4002 #> 1220 yosted01 7346 #> 1221 youngcy01 2960 #> 1222 younger01 6119 #> 1223 youngjo02 3659 #> 1224 yountro01 11008 #> 1225 zachato01 1122 #> 1226 zaungr01 2880 #> 1227 zeileto01 7573 #> 1228 zimmech01 4546
count(baseball, "lg")
#> lg freq #> 1 65 #> 2 AA 171 #> 3 AL 10007 #> 4 FL 37 #> 5 NL 11378 #> 6 PL 32 #> 7 UA 9
# How many stints do players do? count(baseball, "stint")
#> stint freq #> 1 1 19808 #> 2 2 1775 #> 3 3 111 #> 4 4 5
# Count of times each player appeared in each of the years they played count(baseball[1:100,], c("id", "year"))
#> id year freq #> 1 ansonca01 1871 1 #> 2 ansonca01 1872 1 #> 3 ansonca01 1873 1 #> 4 ansonca01 1874 1 #> 5 ansonca01 1875 1 #> 6 ansonca01 1876 1 #> 7 ansonca01 1877 1 #> 8 ansonca01 1878 1 #> 9 bennech01 1878 1 #> 10 burdoja01 1872 1 #> 11 burdoja01 1873 1 #> 12 burdoja01 1874 1 #> 13 burdoja01 1875 1 #> 14 burdoja01 1876 1 #> 15 burdoja01 1877 1 #> 16 burdoja01 1878 1 #> 17 forceda01 1871 1 #> 18 forceda01 1872 2 #> 19 forceda01 1873 1 #> 20 forceda01 1874 1 #> 21 forceda01 1875 1 #> 22 forceda01 1876 2 #> 23 forceda01 1877 1 #> 24 galvipu01 1875 1 #> 25 gerhajo01 1873 1 #> 26 gerhajo01 1874 1 #> 27 gerhajo01 1875 1 #> 28 gerhajo01 1876 1 #> 29 gerhajo01 1877 1 #> 30 hinespa01 1872 1 #> 31 hinespa01 1873 1 #> 32 hinespa01 1874 1 #> 33 hinespa01 1875 1 #> 34 hinespa01 1876 1 #> 35 hinespa01 1877 1 #> 36 jonesch01 1875 2 #> 37 jonesch01 1876 1 #> 38 jonesch01 1877 3 #> 39 mathebo01 1871 1 #> 40 mathebo01 1872 1 #> 41 mathebo01 1873 1 #> 42 mathebo01 1874 1 #> 43 mathebo01 1875 1 #> 44 mathebo01 1876 1 #> 45 mathebo01 1877 1 #> 46 morrijo01 1876 1 #> 47 morrijo01 1877 1 #> 48 nelsoca01 1872 2 #> 49 nelsoca01 1873 1 #> 50 nelsoca01 1874 1 #> 51 nelsoca01 1875 1 #> 52 orourji01 1872 1 #> 53 orourji01 1873 1 #> 54 orourji01 1874 1 #> 55 orourji01 1875 1 #> 56 orourji01 1876 1 #> 57 orourji01 1877 1 #> 58 shaffor01 1874 2 #> 59 shaffor01 1875 1 #> 60 shaffor01 1877 1 #> 61 snydepo01 1873 1 #> 62 snydepo01 1874 1 #> 63 snydepo01 1875 1 #> 64 snydepo01 1876 1 #> 65 snydepo01 1877 1 #> 66 startjo01 1871 1 #> 67 startjo01 1872 1 #> 68 startjo01 1873 1 #> 69 startjo01 1874 1 #> 70 startjo01 1875 1 #> 71 startjo01 1876 1 #> 72 startjo01 1877 1 #> 73 suttoez01 1871 1 #> 74 suttoez01 1872 1 #> 75 suttoez01 1873 1 #> 76 suttoez01 1874 1 #> 77 suttoez01 1875 1 #> 78 suttoez01 1876 1 #> 79 suttoez01 1877 1 #> 80 whitede01 1871 1 #> 81 whitede01 1872 1 #> 82 whitede01 1873 1 #> 83 whitede01 1874 1 #> 84 whitede01 1875 1 #> 85 whitede01 1876 1 #> 86 whitede01 1877 1 #> 87 yorkto01 1871 1 #> 88 yorkto01 1872 1 #> 89 yorkto01 1873 1 #> 90 yorkto01 1874 1 #> 91 yorkto01 1875 1 #> 92 yorkto01 1876 1 #> 93 yorkto01 1877 1
# Count of counts count(count(baseball[1:100,], c("id", "year")), "id", "freq")
#> id freq #> 1 ansonca01 8 #> 2 bennech01 1 #> 3 burdoja01 7 #> 4 forceda01 9 #> 5 galvipu01 1 #> 6 gerhajo01 5 #> 7 hinespa01 6 #> 8 jonesch01 6 #> 9 mathebo01 7 #> 10 morrijo01 2 #> 11 nelsoca01 5 #> 12 orourji01 6 #> 13 shaffor01 4 #> 14 snydepo01 5 #> 15 startjo01 7 #> 16 suttoez01 7 #> 17 whitede01 7 #> 18 yorkto01 7
count(count(baseball, c("id", "year")), "freq")
#> Using freq as weighting variable
#> freq freq.1 #> 1 1 18033 #> 2 2 3328 #> 3 3 318 #> 4 4 20