R version 2.10.1 (2009-12-14) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. [R.app GUI 1.31 (5537) x86_64-apple-darwin9.8.0] > sample(c(0,1),c(0.75,0.25),size=5) Error in sample(c(0, 1), c(0.75, 0.25), size = 5) : invalid 'replace' argument > sample(c(0,1),prob=c(0.75,0.25),size=5) Error in sample(c(0, 1), prob = c(0.75, 0.25), size = 5) : cannot take a sample larger than the population when 'replace = FALSE' > sample(c(0,1),prob=c(0.75,0.25),size=1) [1] 0 > sample(c(0,1),prob=c(0.75,0.25),size=5,replace=T) [1] 0 0 1 0 0 > ?babies No documentation for 'babies' in specified packages and libraries: you could try '??babies' > library(UsingR) > ?babies starting httpd help server ... done > boxplot(gestation~inc,data=babies) > boxplot(gestation~inc,data=babies,subset=(gestation!=999 & inc!=98)) > boxplot(gestation[gestation!=999 & inc!=98]~inc,data=babies) Error in model.frame.default(formula = gestation[gestation != 999 & inc != : variable lengths differ (found for 'inc') > boxplot(gestation[babies$gestation!=999 & babies$inc!=98]~inc,data=babies) Error in model.frame.default(formula = gestation[babies$gestation != 999 & : variable lengths differ (found for 'inc') > attach babies Error: unexpected symbol in "attach babies" > attach(babies) > boxplot(gestation[gestation!=999]~inc) Error in model.frame.default(formula = gestation[gestation != 999] ~ inc) : variable lengths differ (found for 'inc') > boxplot(gestation~inc,data=babies,subset=(gestation!=999 & inc!=98),varwidth=T) > boxplot(gestation~inc,data=babies,subset=(gestation!=999 & inc!=98),varwidth=T) > length(inc==9) [1] 1236 > length(inc==7) [1] 1236 > length(inc) [1] 1236 > inc [1] 1 4 2 8 1 4 98 2 2 2 98 2 2 2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 3 6 8 2 7 5 7 9 5 1 [991] 98 1 1 98 1 98 3 98 6 4 7 2 2 1 6 4 2 1 3 5 2 7 3 1 6 2 9 4 2 4 3 5 4 [1024] 3 4 1 1 6 7 7 5 6 4 5 1 4 4 1 7 4 3 2 4 9 1 6 5 3 2 3 98 5 0 1 98 1 [1057] 4 2 5 98 5 7 98 3 4 3 98 7 98 1 9 1 98 5 98 5 5 3 7 2 0 7 98 7 7 6 4 4 98 [1090] 7 4 5 1 3 5 98 5 7 5 1 5 3 9 7 0 98 4 98 5 7 7 98 2 4 5 3 4 5 2 1 4 3 [1123] 2 98 7 4 1 2 6 8 7 1 3 98 1 98 1 3 5 7 1 7 98 1 4 2 98 2 4 7 3 7 1 0 2 [1156] 1 2 1 1 6 4 5 7 1 2 7 5 98 4 98 1 5 98 3 3 1 1 1 2 7 7 8 3 98 98 2 2 1 [1189] 9 1 5 98 4 2 2 5 3 98 1 1 2 2 8 5 1 7 0 98 2 6 6 2 8 98 4 3 0 9 98 5 2 [1222] 1 98 98 1 9 3 1 3 7 3 4 3 3 1 6 > length(inc[inc==7]) [1] 143 > length(inc[inc==9]) [1] 23 > boxplot(gestation~inc,data=babies[gestation!=999 & inc!=98,],varwidth=T) > ?cancer > cancer $stomach [1] 124 42 25 45 412 51 1112 46 103 876 146 340 396 $bronchus [1] 81 461 20 450 246 166 63 64 155 859 151 166 37 223 138 72 245 $colon [1] 248 377 189 1843 180 537 519 455 406 365 942 776 372 163 101 20 283 $ovary [1] 1234 89 201 356 2970 456 $breast [1] 1235 24 1581 1166 40 727 3808 791 1804 3460 719 > median(cancer) Error in sort.list(x, partial = half) : 'x' must be atomic for 'sort.list' Have you called 'sort' on a list? > mean(cancer) [1] NA Warning message: In mean.default(cancer) : argument is not numeric or logical: returning NA > sapply(cancer,mean) stomach bronchus colon ovary breast 286.0000 211.5882 457.4118 884.3333 1395.9091 > sapply(cancer,median) stomach bronchus colon ovary breast 124 155 372 406 1166 > stack(cancer) values ind 1 124 stomach 2 42 stomach 3 25 stomach 4 45 stomach 5 412 stomach 6 51 stomach 7 1112 stomach 8 46 stomach 9 103 stomach 10 876 stomach 11 146 stomach 12 340 stomach 13 396 stomach 14 81 bronchus 15 461 bronchus 16 20 bronchus 17 450 bronchus 18 246 bronchus 19 166 bronchus 20 63 bronchus 21 64 bronchus 22 155 bronchus 23 859 bronchus 24 151 bronchus 25 166 bronchus 26 37 bronchus 27 223 bronchus 28 138 bronchus 29 72 bronchus 30 245 bronchus 31 248 colon 32 377 colon 33 189 colon 34 1843 colon 35 180 colon 36 537 colon 37 519 colon 38 455 colon 39 406 colon 40 365 colon 41 942 colon 42 776 colon 43 372 colon 44 163 colon 45 101 colon 46 20 colon 47 283 colon 48 1234 ovary 49 89 ovary 50 201 ovary 51 356 ovary 52 2970 ovary 53 456 ovary 54 1235 breast 55 24 breast 56 1581 breast 57 1166 breast 58 40 breast 59 727 breast 60 3808 breast 61 791 breast 62 1804 breast 63 3460 breast 64 719 breast > x=stack(cancer) > unstack(x) $breast [1] 1235 24 1581 1166 40 727 3808 791 1804 3460 719 $bronchus [1] 81 461 20 450 246 166 63 64 155 859 151 166 37 223 138 72 245 $colon [1] 248 377 189 1843 180 537 519 455 406 365 942 776 372 163 101 20 283 $ovary [1] 1234 89 201 356 2970 456 $stomach [1] 124 42 25 45 412 51 1112 46 103 876 146 340 396 > x values ind 1 124 stomach 2 42 stomach 3 25 stomach 4 45 stomach 5 412 stomach 6 51 stomach 7 1112 stomach 8 46 stomach 9 103 stomach 10 876 stomach 11 146 stomach 12 340 stomach 13 396 stomach 14 81 bronchus 15 461 bronchus 16 20 bronchus 17 450 bronchus 18 246 bronchus 19 166 bronchus 20 63 bronchus 21 64 bronchus 22 155 bronchus 23 859 bronchus 24 151 bronchus 25 166 bronchus 26 37 bronchus 27 223 bronchus 28 138 bronchus 29 72 bronchus 30 245 bronchus 31 248 colon 32 377 colon 33 189 colon 34 1843 colon 35 180 colon 36 537 colon 37 519 colon 38 455 colon 39 406 colon 40 365 colon 41 942 colon 42 776 colon 43 372 colon 44 163 colon 45 101 colon 46 20 colon 47 283 colon 48 1234 ovary 49 89 ovary 50 201 ovary 51 356 ovary 52 2970 ovary 53 456 ovary 54 1235 breast 55 24 breast 56 1581 breast 57 1166 breast 58 40 breast 59 727 breast 60 3808 breast 61 791 breast 62 1804 breast 63 3460 breast 64 719 breast > split(x,x$ind) $breast values ind 54 1235 breast 55 24 breast 56 1581 breast 57 1166 breast 58 40 breast 59 727 breast 60 3808 breast 61 791 breast 62 1804 breast 63 3460 breast 64 719 breast $bronchus values ind 14 81 bronchus 15 461 bronchus 16 20 bronchus 17 450 bronchus 18 246 bronchus 19 166 bronchus 20 63 bronchus 21 64 bronchus 22 155 bronchus 23 859 bronchus 24 151 bronchus 25 166 bronchus 26 37 bronchus 27 223 bronchus 28 138 bronchus 29 72 bronchus 30 245 bronchus $colon values ind 31 248 colon 32 377 colon 33 189 colon 34 1843 colon 35 180 colon 36 537 colon 37 519 colon 38 455 colon 39 406 colon 40 365 colon 41 942 colon 42 776 colon 43 372 colon 44 163 colon 45 101 colon 46 20 colon 47 283 colon $ovary values ind 48 1234 ovary 49 89 ovary 50 201 ovary 51 356 ovary 52 2970 ovary 53 456 ovary $stomach values ind 1 124 stomach 2 42 stomach 3 25 stomach 4 45 stomach 5 412 stomach 6 51 stomach 7 1112 stomach 8 46 stomach 9 103 stomach 10 876 stomach 11 146 stomach 12 340 stomach 13 396 stomach > cancer $stomach [1] 124 42 25 45 412 51 1112 46 103 876 146 340 396 $bronchus [1] 81 461 20 450 246 166 63 64 155 859 151 166 37 223 138 72 245 $colon [1] 248 377 189 1843 180 537 519 455 406 365 942 776 372 163 101 20 283 $ovary [1] 1234 89 201 356 2970 456 $breast [1] 1235 24 1581 1166 40 727 3808 791 1804 3460 719 > median(cancer) Error in sort.list(x, partial = half) : 'x' must be atomic for 'sort.list' Have you called 'sort' on a list? > cance Error: object 'cance' not found > cancer $stomach [1] 124 42 25 45 412 51 1112 46 103 876 146 340 396 $bronchus [1] 81 461 20 450 246 166 63 64 155 859 151 166 37 223 138 72 245 $colon [1] 248 377 189 1843 180 537 519 455 406 365 942 776 372 163 101 20 283 $ovary [1] 1234 89 201 356 2970 456 $breast [1] 1235 24 1581 1166 40 727 3808 791 1804 3460 719 > sapply(cancer,median) stomach bronchus colon ovary breast 124 155 372 406 1166 > x values ind 1 124 stomach 2 42 stomach 3 25 stomach 4 45 stomach 5 412 stomach 6 51 stomach 7 1112 stomach 8 46 stomach 9 103 stomach 10 876 stomach 11 146 stomach 12 340 stomach 13 396 stomach 14 81 bronchus 15 461 bronchus 16 20 bronchus 17 450 bronchus 18 246 bronchus 19 166 bronchus 20 63 bronchus 21 64 bronchus 22 155 bronchus 23 859 bronchus 24 151 bronchus 25 166 bronchus 26 37 bronchus 27 223 bronchus 28 138 bronchus 29 72 bronchus 30 245 bronchus 31 248 colon 32 377 colon 33 189 colon 34 1843 colon 35 180 colon 36 537 colon 37 519 colon 38 455 colon 39 406 colon 40 365 colon 41 942 colon 42 776 colon 43 372 colon 44 163 colon 45 101 colon 46 20 colon 47 283 colon 48 1234 ovary 49 89 ovary 50 201 ovary 51 356 ovary 52 2970 ovary 53 456 ovary 54 1235 breast 55 24 breast 56 1581 breast 57 1166 breast 58 40 breast 59 727 breast 60 3808 breast 61 791 breast 62 1804 breast 63 3460 breast 64 719 breast > tapply(x$values,x$ind,median) breast bronchus colon ovary stomach 1166 155 372 406 124 > > sapply(cancer,median) stomach bronchus colon ovary breast 124 155 372 406 1166 > subset(babies,subset=(gestation!=999))[1:10,] id pluralty outcome date gestation sex wt parity race age ed ht wt1 drace dage ded dht dwt marital 1 15 5 1 1411 284 1 120 1 8 27 5 62 100 8 31 5 65 110 1 2 20 5 1 1499 282 1 113 2 0 33 5 64 135 0 38 5 70 148 1 3 58 5 1 1576 279 1 128 1 0 28 2 64 115 5 32 1 99 999 1 5 72 5 1 1425 282 1 108 1 0 23 5 67 125 0 24 5 99 999 1 6 100 5 1 1673 286 1 136 4 0 25 2 62 93 3 28 2 64 130 1 7 102 5 1 1449 244 1 138 4 7 33 2 62 178 7 37 4 99 999 1 8 129 5 1 1562 245 1 132 2 7 23 1 65 140 7 23 4 71 192 1 9 142 5 1 1408 289 1 120 3 0 25 4 62 125 3 26 1 70 180 0 10 148 5 1 1568 299 1 143 3 0 30 5 66 136 0 34 5 99 999 1 11 164 5 1 1554 351 1 140 2 0 27 5 68 120 5 28 4 99 999 1 inc smoke time number 1 1 0 0 0 2 4 0 0 0 3 2 1 1 1 5 1 1 1 5 6 4 2 2 2 7 98 0 0 0 8 2 0 0 0 9 2 0 0 0 10 2 1 1 4 11 98 3 4 2 > subset(babies,subset=(gestation!=999))[1:10,][1:5,] id pluralty outcome date gestation sex wt parity race age ed ht wt1 drace dage ded dht dwt marital 1 15 5 1 1411 284 1 120 1 8 27 5 62 100 8 31 5 65 110 1 2 20 5 1 1499 282 1 113 2 0 33 5 64 135 0 38 5 70 148 1 3 58 5 1 1576 279 1 128 1 0 28 2 64 115 5 32 1 99 999 1 5 72 5 1 1425 282 1 108 1 0 23 5 67 125 0 24 5 99 999 1 6 100 5 1 1673 286 1 136 4 0 25 2 62 93 3 28 2 64 130 1 inc smoke time number 1 1 0 0 0 2 4 0 0 0 3 2 1 1 1 5 1 1 1 5 6 4 2 2 2 > subset(babies,subset=(gestation!=999))[1:5,] id pluralty outcome date gestation sex wt parity race age ed ht wt1 drace dage ded dht dwt marital 1 15 5 1 1411 284 1 120 1 8 27 5 62 100 8 31 5 65 110 1 2 20 5 1 1499 282 1 113 2 0 33 5 64 135 0 38 5 70 148 1 3 58 5 1 1576 279 1 128 1 0 28 2 64 115 5 32 1 99 999 1 5 72 5 1 1425 282 1 108 1 0 23 5 67 125 0 24 5 99 999 1 6 100 5 1 1673 286 1 136 4 0 25 2 62 93 3 28 2 64 130 1 inc smoke time number 1 1 0 0 0 2 4 0 0 0 3 2 1 1 1 5 1 1 1 5 6 4 2 2 2 > babies[babies$gestation!=999,][1:10,] id pluralty outcome date gestation sex wt parity race age ed ht wt1 drace dage ded dht dwt marital 1 15 5 1 1411 284 1 120 1 8 27 5 62 100 8 31 5 65 110 1 2 20 5 1 1499 282 1 113 2 0 33 5 64 135 0 38 5 70 148 1 3 58 5 1 1576 279 1 128 1 0 28 2 64 115 5 32 1 99 999 1 5 72 5 1 1425 282 1 108 1 0 23 5 67 125 0 24 5 99 999 1 6 100 5 1 1673 286 1 136 4 0 25 2 62 93 3 28 2 64 130 1 7 102 5 1 1449 244 1 138 4 7 33 2 62 178 7 37 4 99 999 1 8 129 5 1 1562 245 1 132 2 7 23 1 65 140 7 23 4 71 192 1 9 142 5 1 1408 289 1 120 3 0 25 4 62 125 3 26 1 70 180 0 10 148 5 1 1568 299 1 143 3 0 30 5 66 136 0 34 5 99 999 1 11 164 5 1 1554 351 1 140 2 0 27 5 68 120 5 28 4 99 999 1 inc smoke time number 1 1 0 0 0 2 4 0 0 0 3 2 1 1 1 5 1 1 1 5 6 4 2 2 2 7 98 0 0 0 8 2 0 0 0 9 2 0 0 0 10 2 1 1 4 11 98 3 4 2 > x=babies[babies$gestation!=999,][1:50,] > x id pluralty outcome date gestation sex wt parity race age ed ht wt1 drace dage ded dht dwt marital 1 15 5 1 1411 284 1 120 1 8 27 5 62 100 8 31 5 65 110 1 2 20 5 1 1499 282 1 113 2 0 33 5 64 135 0 38 5 70 148 1 3 58 5 1 1576 279 1 128 1 0 28 2 64 115 5 32 1 99 999 1 5 72 5 1 1425 282 1 108 1 0 23 5 67 125 0 24 5 99 999 1 6 100 5 1 1673 286 1 136 4 0 25 2 62 93 3 28 2 64 130 1 7 102 5 1 1449 244 1 138 4 7 33 2 62 178 7 37 4 99 999 1 8 129 5 1 1562 245 1 132 2 7 23 1 65 140 7 23 4 71 192 1 9 142 5 1 1408 289 1 120 3 0 25 4 62 125 3 26 1 70 180 0 10 148 5 1 1568 299 1 143 3 0 30 5 66 136 0 34 5 99 999 1 11 164 5 1 1554 351 1 140 2 0 27 5 68 120 5 28 4 99 999 1 12 171 5 1 1593 282 1 144 4 0 32 2 64 124 0 36 1 74 185 1 13 175 5 1 1491 279 1 141 3 0 23 1 63 128 5 28 2 99 999 1 14 183 5 1 1446 281 1 110 5 8 36 5 61 99 0 32 5 99 999 1 15 194 5 1 1524 273 1 114 3 7 30 2 63 154 7 42 0 99 999 1 16 195 5 1 1501 285 1 115 4 7 38 2 63 130 7 37 0 71 205 1 17 207 5 1 1481 255 1 92 3 4 25 7 65 125 7 28 1 99 999 1 18 217 5 1 1605 261 1 115 3 3 33 2 60 125 3 33 2 70 140 1 19 239 5 1 1431 261 1 144 2 0 33 2 68 170 5 35 4 99 999 1 20 240 5 1 1647 288 1 119 3 0 43 2 66 142 0 45 2 73 195 1 21 253 5 1 1553 270 1 105 3 9 22 2 56 93 10 38 1 99 999 1 22 274 5 1 1554 274 1 115 1 4 27 4 67 175 5 26 4 73 180 1 23 291 5 1 1624 287 1 137 1 0 25 4 66 145 0 25 5 70 150 1 24 294 5 1 1630 276 1 122 6 7 30 1 68 182 9 38 1 73 196 1 25 310 5 1 1367 294 1 131 2 7 23 2 65 122 7 23 4 99 999 1 26 337 5 1 1589 261 1 103 6 4 27 1 65 112 4 29 1 99 999 1 27 357 5 1 1533 280 1 146 1 6 26 0 58 106 6 29 2 68 200 1 28 365 5 1 1464 266 1 114 2 0 20 2 65 175 0 25 2 99 999 1 29 375 5 1 1708 292 1 125 3 3 32 2 65 125 0 29 5 67 135 1 30 376 5 1 1710 274 1 114 2 0 28 5 66 132 0 31 5 70 168 1 31 404 5 1 1358 270 1 122 2 0 26 2 61 105 0 26 2 99 999 1 32 428 5 1 1452 278 1 93 3 7 34 1 61 146 7 37 2 70 140 1 33 432 5 1 1498 268 1 130 2 0 30 2 66 123 0 46 2 66 210 1 34 477 5 1 1669 275 1 119 1 10 23 2 60 105 9 25 2 70 190 1 35 493 5 1 1616 281 1 113 3 0 24 4 65 120 0 24 5 99 999 1 36 539 5 1 1521 283 1 134 1 0 22 2 67 130 1 22 2 71 185 1 37 556 5 1 1670 279 1 107 1 5 24 5 63 115 5 31 5 71 160 1 38 563 5 1 1482 288 1 134 2 0 23 2 63 92 0 26 1 71 178 1 39 591 5 1 1437 267 1 122 1 0 27 4 65 101 1 29 5 71 200 1 40 609 5 1 1708 282 1 128 6 0 31 2 65 999 0 31 4 99 999 1 41 646 5 1 1627 293 1 129 2 0 30 4 61 160 0 29 4 67 130 1 42 657 5 1 1602 278 1 110 3 0 23 4 63 177 0 25 5 99 999 1 43 689 5 1 1585 302 1 138 4 5 26 1 99 999 6 41 9 65 168 1 44 745 5 1 1575 270 1 111 4 6 27 1 61 119 6 33 2 66 178 1 45 764 5 1 1462 248 1 87 10 0 37 1 65 130 0 40 2 72 155 1 46 767 5 1 1467 274 1 143 3 0 27 4 63 110 2 31 5 99 999 1 47 773 5 1 1438 294 1 155 6 7 32 2 66 150 9 35 2 69 150 1 48 798 5 1 1414 272 1 110 2 8 25 1 60 90 8 34 2 66 150 1 49 806 5 1 1427 275 1 122 1 0 26 5 66 147 0 25 5 71 170 1 50 813 5 1 1696 291 1 145 4 10 26 4 63 119 3 29 4 67 165 1 51 818 5 1 1369 258 1 115 4 0 26 7 62 130 0 30 3 99 999 1 inc smoke time number 1 1 0 0 0 2 4 0 0 0 3 2 1 1 1 5 1 1 1 5 6 4 2 2 2 7 98 0 0 0 8 2 0 0 0 9 2 0 0 0 10 2 1 1 4 11 98 3 4 2 12 2 1 1 1 13 2 1 1 1 14 2 1 1 2 15 1 0 0 0 16 1 0 0 0 17 1 1 1 5 18 4 1 1 5 19 7 0 0 0 20 5 1 1 6 21 3 0 0 0 22 3 1 1 9 23 2 2 2 5 24 2 0 0 0 25 2 2 2 1 26 6 1 1 5 27 2 2 2 1 28 2 1 1 2 29 1 0 0 0 30 6 1 1 5 31 3 0 0 0 32 4 2 2 1 33 7 3 4 1 34 2 0 0 0 35 0 0 0 0 36 2 0 0 0 37 4 3 4 5 38 1 1 1 5 39 7 1 1 1 40 3 0 0 0 41 3 0 0 0 42 2 0 0 0 43 98 1 1 5 44 2 2 2 1 45 8 1 1 5 46 4 1 1 7 47 1 3 3 1 48 2 0 0 0 49 1 0 0 0 50 4 1 1 1 51 2 0 0 0 > split(x$gestation,x$smoke) $`0` [1] 284 282 244 245 289 273 285 261 270 276 292 270 275 281 283 282 293 278 272 275 258 $`1` [1] 279 282 299 282 279 281 255 261 288 274 261 266 274 288 267 302 248 274 291 $`2` [1] 286 287 294 280 278 270 $`3` [1] 351 268 279 294 > tapply(x$gestation,x$smoke,mean) 0 1 2 3 274.6667 276.3684 282.5000 298.0000 > boxplot(x$gestation) > boxplot(split(x$gestation,x$smoke)) > ?babies > boxplot(x$gestation~x$smoke) > ewr Year Month AA CO DL HP NW TW UA US inorout 1 2000 Nov 8.6 8.3 8.6 10.4 8.1 9.1 8.4 7.6 in 2 2000 Oct 8.5 8.0 8.4 11.2 8.2 8.5 8.5 7.8 in 3 2000 Sep 8.1 8.5 8.4 10.2 8.3 8.6 8.2 7.6 in 4 2000 Aug 8.9 9.1 9.2 14.5 9.0 10.3 9.2 8.7 in 5 2000 Jul 8.3 8.9 8.2 11.5 8.8 9.1 9.2 8.2 in 6 2000 Jun 8.8 9.0 8.8 14.9 8.4 10.8 8.9 8.3 in 7 2000 May 8.1 8.8 7.9 9.8 7.8 7.5 8.1 8.3 in 8 2000 Apr 8.7 8.6 8.1 9.8 8.6 8.1 8.5 9.5 in 9 2000 Mar 8.8 8.4 7.8 8.0 8.7 6.4 8.2 7.9 in 10 2000 Feb 8.7 8.9 7.6 9.3 8.5 6.9 8.2 7.5 in 11 2000 Jan 9.4 9.4 8.5 9.9 9.4 6.3 8.6 7.7 in 12 1999 Dec 8.6 8.7 7.8 9.3 8.1 6.0 7.8 7.1 in 13 1999 Nov 8.3 9.3 8.5 10.4 8.9 6.1 8.0 7.1 in 14 1999 Oct 7.9 9.4 8.1 10.8 9.3 5.9 8.0 7.2 in 15 1999 Sep 8.4 9.3 8.1 10.3 9.0 6.2 8.3 7.4 in 16 1999 Aug 8.9 10.0 9.0 10.9 8.8 6.5 9.1 8.1 in 17 1999 Jul 8.6 11.0 9.0 12.5 9.2 6.2 8.3 7.6 in 18 1999 Jun 8.8 10.6 8.4 10.3 9.0 6.0 7.9 7.5 in 19 1999 May 8.7 8.9 8.1 9.7 8.3 6.0 8.0 8.2 in 20 1999 Apr 8.4 8.8 8.4 9.9 8.1 6.0 8.5 7.6 in 21 1999 Mar 8.6 9.0 7.7 9.5 8.4 6.2 8.2 7.2 in 22 1999 Feb 8.9 8.9 7.7 9.1 8.4 6.2 8.2 7.5 in 23 1999 Jan 9.1 10.6 7.6 12.2 8.5 5.7 8.1 6.9 in 24 2000 Nov 22.7 25.3 21.8 23.0 19.7 21.8 23.9 19.4 out 25 2000 Oct 24.8 27.8 22.7 25.3 21.6 23.9 24.5 21.6 out 26 2000 Sep 26.4 30.8 25.1 27.9 22.4 27.1 27.1 23.7 out 27 2000 Aug 33.7 37.6 31.8 34.6 26.1 32.9 33.3 27.6 out 28 2000 Jul 29.3 33.4 26.5 27.6 23.2 28.9 30.6 23.1 out 29 2000 Jun 33.4 36.0 29.5 31.3 24.8 33.0 31.7 27.8 out 30 2000 May 26.4 30.8 25.5 29.8 22.8 31.1 28.0 22.7 out 31 2000 Apr 26.2 30.9 25.1 28.6 21.9 24.8 26.5 24.0 out 32 2000 Mar 24.2 27.0 23.0 24.3 21.4 21.6 23.9 21.1 out 33 2000 Feb 26.3 27.7 22.8 25.4 22.0 21.9 24.1 22.1 out 34 2000 Jan 26.3 28.7 22.6 26.0 21.2 21.6 24.4 20.8 out 35 1999 Dec 23.2 26.3 22.2 23.8 19.9 21.9 23.9 20.6 out 36 1999 Nov 22.9 27.9 22.4 25.5 21.3 22.6 24.0 21.4 out 37 1999 Oct 25.6 30.5 24.7 25.4 22.7 23.6 26.4 22.5 out 38 1999 Sep 26.6 30.6 24.9 30.3 23.0 23.3 26.7 24.3 out 39 1999 Aug 29.3 33.9 29.2 35.2 25.5 27.1 29.5 25.4 out 40 1999 Jul 35.2 40.4 31.4 38.6 31.9 33.5 33.9 30.1 out 41 1999 Jun 30.2 34.1 26.9 32.7 25.0 27.0 29.1 25.6 out 42 1999 May 29.7 34.7 26.7 32.5 24.5 26.0 30.4 25.9 out 43 1999 Apr 27.0 31.3 24.4 31.3 24.1 25.1 28.3 23.3 out 44 1999 Mar 24.0 28.6 21.8 26.1 21.8 20.5 23.7 20.4 out 45 1999 Feb 24.1 26.7 21.9 24.8 20.7 21.1 23.8 20.6 out 46 1999 Jan 24.8 29.5 22.2 27.4 21.4 24.0 23.7 20.2 out > mean(ewr) Year Month AA CO DL HP NW TW UA 1999.47826 NA 17.83478 20.01957 16.63043 19.60435 15.79783 16.28043 17.69130 US inorout 15.49348 NA Warning messages: 1: In mean.default(X[[2L]], ...) : argument is not numeric or logical: returning NA 2: In mean.default(X[[11L]], ...) : argument is not numeric or logical: returning NA > median(ewr) structure(c("NULL", NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1 NULL 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 Warning message: In format.data.frame(x, digits = digits, na.encode = FALSE) : corrupt data frame: columns will be truncated or padded with NAs > library(lattice) \ > > histogram(~wt | factor(smoke),data=babies,subset=(wt!=999)) > histogram(~wt | factor(smoke),data=babies,subset=(wt!=999),type='density') > histogram(~wt | factor(smoke),data=babies,subset=(wt!=999)) > histogram(~wt | factor(smoke),data=babies,subset=(wt!=999),type='density') > histogram(~wt | factor(smoke),data=babies,subset=(wt!=999)) > densityplot(~wt|factor(smoke),data=babies) > histogram(~wt | factor(smoke),data=babies,subset=(wt!=999)) > histogram(~wt | factor(smoke),data=babies,subset=(wt!=999),type='density') > densityplot(~wt|factor(smoke),data=babies) > bwplot(gestation~factor(inc),data=babies,subset=(gestation!=999)) > boxplot(split(x$gestation,x$inc)) > boxplot(split(x[x$inc!=98]$gestation,x[x$inc!=98]$inc)) Error in `[.data.frame`(x, x$inc != 98) : undefined columns selected > boxplot(split(x[x$inc!=98,]$gestation,x[x$inc!=98,]$inc)) > bwplot(gestation~factor(inc),data=babies,subset=(gestation!=999)) > boxplot(split(x[x$gestation!=999,]$gestation,x[x$gestation!=999,]$inc)) > bwplot(gestation~factor(inc),data=babies,subset=(gestation!=999)) > boxplot(split(x[x$gestation!=999,]$gestation,x[x$gestation!=999,]$inc)) > bwplot(gestation~factor(inc)|factor(smoke),data=babies,subset=(gestation!=999)) > xyplot(wt~gestation | factor(smoke), data=babies, subset=(wt!=999 & gestation!=999)) > xyplot(wt~gestation | factor(smoke), data=babies, subset=(wt != 999 & gestation != 999), panel=plot.regression) Error in xyplot.formula(wt ~ gestation | factor(smoke), data = babies, : object 'plot.regression' not found > plot.regression = function(x,y) { panel.xyplot(x,y); panel.abline(lm(y~x)); } > xyplot(wt~gestation | factor(smoke), data=babies, subset=(wt != 999 & gestation != 999), panel=plot.regression) > plot(wt~gestation) > plot(wt[babies$gestation!=999]~gestation[babies$gestation!=999]) > length(babies) [1] 23 > length(babies$wt) [1] 1236 > plot(wt[gestation!=999]~gestation[gestation!=999]) > res=lm(wt[gestation!=999]~gestation[gestation!=999]) > abline(res) > plot(log(wt[gestation!=999])~log(gestation[gestation!=999])) > res=lm(log(wt[gestation!=999])~log(gestation[gestation!=999])) > abline(res) > sample(c(0,1),prob=c(.66,.33)) [1] 0 1 > sample(c(0,1),prob=c(.66,.33)) [1] 1 0 > sample(c(0,1),prob=c(.66,.33)) [1] 1 0 > sample(c(0,1),prob=c(.66,.33),size=1) [1] 0 > sample(c(0,1),prob=c(.66,.33),size=1) [1] 0 > sample(c(0,1),prob=c(.66,.33),size=1) [1] 0 > sample(c(0,1),prob=c(.66,.33),size=1) [1] 1 > sample(c(0,1),prob=c(.66,.33),size=1) [1] 0 > sample(c(0,1),prob=c(.66,.33),size=1) [1] 0 > sample(c(0,1),prob=c(.66,.33),size=1) [1] 0 > sample(c(0,1),prob=c(.66,.33),size=1) [1] 0 > > sample(c(0,1),prob=c(.66,.33),size=1) [1] 0 > sample(c(0,1),prob=c(.66,.33),size=1) [1] 0 > sample(c(0,1),prob=c(.66,.33),size=1) [1] 0 > sample(c(0,1),prob=c(.66,.33),size=1) [1] 0 > sample(c(0,1),prob=c(.66,.33),size=1) [1] 1 > sample(c(0,1),prob=c(.66,.33),size=5) Error in sample(c(0, 1), prob = c(0.66, 0.33), size = 5) : cannot take a sample larger than the population when 'replace = FALSE' > sample(c(0,1),prob=c(.66,.33),size=5,rep=T) [1] 0 0 0 1 1 > sample(c(0,1),prob=c(.66,.33),size=50,rep=T) [1] 1 0 0 1 1 1 0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 0 0 1 1 1 0 0 0 0 1 0 0 1 1 1 1 0 > x=sample(c(0,1),prob=c(.66,.33),size=50,rep=T) > x [1] 0 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 1 0 0 0 1 1 0 0 0 0 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 0 0 0 1 0 1 1 0 > lenght(x[x==1)])/50 Error: unexpected ')' in "lenght(x[x==1)" > lenght(x[x==1])/50 Error: could not find function "lenght" > lengtj(x[x==1])/50 Error: could not find function "lengtj" > length(x[x==1])/50 [1] 0.38 > n=50; x=sample(c(0,1),prob=c(.66,.33),size=n,rep=T); length(x[x==1])/n [1] 0.3 > n=50; x=sample(c(0,1),prob=c(.66,.33),size=n,rep=T); length(x[x==1])/n [1] 0.3 > n=50; x=sample(c(0,1),prob=c(.66,.33),size=n,rep=T); length(x[x==1])/n [1] 0.2 > n=50; x=sample(c(0,1),prob=c(.66,.33),size=n,rep=T); length(x[x==1])/n [1] 0.38 > n=5; x=sample(c(0,1),prob=c(.66,.33),size=n,rep=T); length(x[x==1])/n [1] 0.4 > n=5; x=sample(c(0,1),prob=c(.66,.33),size=n,rep=T); length(x[x==1])/n [1] 0.2 > n=5; x=sample(c(0,1),prob=c(.66,.33),size=n,rep=T); length(x[x==1])/n [1] 0.2 > n=5; x=sample(c(0,1),prob=c(.66,.33),size=n,rep=T); length(x[x==1])/n [1] 0.2 > n=5; x=sample(c(0,1),prob=c(.66,.33),size=n,rep=T); length(x[x==1])/n [1] 0.2 > n=500; x=sample(c(0,1),prob=c(.66,.33),size=n,rep=T); length(x[x==1])/n [1] 0.336 > n=5000; x=sample(c(0,1),prob=c(.66,.33),size=n,rep=T); length(x[x==1])/n [1] 0.3336 > sample(1:6,size=1) [1] 6 > sample(1:6,size=1) [1] 6 > sample(1:6,size=1) [1] 3 > sample(1:6,size=1) [1] 2 > sample(1:6,size=1) [1] 2 > sample(1:6,size=1) [1] 3 > sample(1:6,size=1) + sample(1:6,size=1) [1] 10 > min(sample(1:6,size=1),sample(1:6,size=1)) [1] 4 > min(sample(1:6,size=1),sample(1:6,size=1)) [1] 1 > min(sample(1:6,size=1),sample(1:6,size=1)) [1] 1 > min(sample(1:6,size=1),sample(1:6,size=1)) [1] 3 > min(sample(1:6,size=1),sample(1:6,size=1)) [1] 2 > sample(1:6,size=1)==5 [1] FALSE > sample(1:6,size=1)==5 [1] FALSE > sample(1:6,size=1)==5 [1] FALSE > sample(1:6,size=1)==5 [1] FALSE > sample(1:6,size=1)==5 [1] FALSE > sample(1:6,size=1)==5 [1] FALSE > sample(1:6,size=1)==5 [1] TRUE > sample(1:6,size=1)==5 [1] FALSE > sample(1:6,size=1)==5 [1] TRUE > sample(1:6,size=1)==5 [1] FALSE > sample(1:6,size=1)==5 [1] FALSE > sample(1:6,size=1)==5 [1] FALSE > sample(1:6,size=1)==5 [1] FALSE > sample(1:6,size=1)==5 [1] FALSE >