-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathreg-tests-2.Rout.save
7811 lines (7233 loc) · 203 KB
/
reg-tests-2.Rout.save
1
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
R version 3.3.1 RC (2016-06-14 r70774) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
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.
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.
> ## Regression tests for which the printed output is the issue
> ### _and_ must work (no Recommended packages, please)
>
> pdf("reg-tests-2.pdf", encoding = "ISOLatin1.enc")
>
> ## force standard handling for data frames
> options(stringsAsFactors=TRUE)
> options(useFancyQuotes=FALSE)
>
> ### moved from various .Rd files
> ## abbreviate
> for(m in 1:5) {
+ cat("\n",m,":\n")
+ print(as.vector(abbreviate(state.name, minl=m)))
+ }
1 :
[1] "Alb" "Als" "Arz" "Ark" "Clf" "Clr" "Cn" "D" "F" "G"
[11] "H" "Id" "Il" "In" "Iw" "Kns" "Knt" "L" "Man" "Mr"
[21] "Mssc" "Mc" "Mnn" "Msss" "Mssr" "Mnt" "Nb" "Nv" "NH" "NJ"
[31] "NM" "NY" "NC" "ND" "Oh" "Ok" "Or" "P" "RI" "SC"
[41] "SD" "Tn" "Tx" "U" "Vrm" "Vrg" "Wsh" "WV" "Wsc" "Wy"
2 :
[1] "Alb" "Als" "Arz" "Ark" "Clf" "Clr" "Cn" "Dl" "Fl" "Gr"
[11] "Hw" "Id" "Il" "In" "Iw" "Kns" "Knt" "Ls" "Man" "Mr"
[21] "Mssc" "Mc" "Mnn" "Msss" "Mssr" "Mnt" "Nb" "Nv" "NH" "NJ"
[31] "NM" "NY" "NC" "ND" "Oh" "Ok" "Or" "Pn" "RI" "SC"
[41] "SD" "Tn" "Tx" "Ut" "Vrm" "Vrg" "Wsh" "WV" "Wsc" "Wy"
3 :
[1] "Alb" "Als" "Arz" "Ark" "Clf" "Clr" "Cnn" "Dlw" "Flr" "Grg"
[11] "Haw" "Idh" "Ill" "Ind" "Iow" "Kns" "Knt" "Lsn" "Man" "Mry"
[21] "Mssc" "Mch" "Mnn" "Msss" "Mssr" "Mnt" "Nbr" "Nvd" "NwH" "NwJ"
[31] "NwM" "NwY" "NrC" "NrD" "Ohi" "Okl" "Org" "Pnn" "RhI" "StC"
[41] "StD" "Tnn" "Txs" "Uth" "Vrm" "Vrg" "Wsh" "WsV" "Wsc" "Wym"
4 :
[1] "Albm" "Alsk" "Arzn" "Arkn" "Clfr" "Clrd" "Cnnc" "Dlwr" "Flrd" "Gerg"
[11] "Hawa" "Idah" "Illn" "Indn" "Iowa" "Knss" "Kntc" "Losn" "Main" "Mryl"
[21] "Mssc" "Mchg" "Mnns" "Msss" "Mssr" "Mntn" "Nbrs" "Nevd" "NwHm" "NwJr"
[31] "NwMx" "NwYr" "NrtC" "NrtD" "Ohio" "Oklh" "Orgn" "Pnns" "RhdI" "SthC"
[41] "SthD" "Tnns" "Texs" "Utah" "Vrmn" "Vrgn" "Wshn" "WstV" "Wscn" "Wymn"
5 :
[1] "Alabm" "Alask" "Arizn" "Arkns" "Clfrn" "Colrd" "Cnnct" "Delwr" "Flord"
[10] "Georg" "Hawai" "Idaho" "Illns" "Indin" "Iowa" "Kanss" "Kntck" "Lousn"
[19] "Maine" "Mryln" "Mssch" "Mchgn" "Mnnst" "Mssss" "Missr" "Montn" "Nbrsk"
[28] "Nevad" "NwHmp" "NwJrs" "NwMxc" "NwYrk" "NrthC" "NrthD" "Ohio" "Oklhm"
[37] "Oregn" "Pnnsy" "RhdIs" "SthCr" "SthDk" "Tnnss" "Texas" "Utah" "Vrmnt"
[46] "Virgn" "Wshng" "WstVr" "Wscns" "Wymng"
>
> ## apply
> x <- cbind(x1 = 3, x2 = c(4:1, 2:5))
> dimnames(x)[[1]] <- letters[1:8]
> apply(x, 2, summary) # 6 x n matrix
x1 x2
Min. 3 1
1st Qu. 3 2
Median 3 3
Mean 3 3
3rd Qu. 3 4
Max. 3 5
> apply(x, 1, quantile)# 5 x n matrix
a b c d e f g h
0% 3.00 3 2.00 1.0 2.00 3 3.00 3.0
25% 3.25 3 2.25 1.5 2.25 3 3.25 3.5
50% 3.50 3 2.50 2.0 2.50 3 3.50 4.0
75% 3.75 3 2.75 2.5 2.75 3 3.75 4.5
100% 4.00 3 3.00 3.0 3.00 3 4.00 5.0
>
> d.arr <- 2:5
> arr <- array(1:prod(d.arr), d.arr,
+ list(NULL,letters[1:d.arr[2]],NULL,paste("V",4+1:d.arr[4],sep="")))
> aa <- array(1:20,c(2,2,5))
> str(apply(aa[FALSE,,,drop=FALSE], 1, dim))# empty integer, `incorrect' dim.
int(0)
> stopifnot(
+ apply(arr, 1:2, sum) == t(apply(arr, 2:1, sum)),
+ aa == apply(aa,2:3,function(x) x),
+ all.equal(apply(apply(aa,2:3, sum),2,sum),
+ 10+16*0:4, tolerance = 4*.Machine$double.eps)
+ )
> marg <- list(1:2, 2:3, c(2,4), c(1,3), 2:4, 1:3, 1:4)
> for(m in marg) print(apply(arr, print(m), sum))
[1] 1 2
a b c
[1,] 1160 1200 1240
[2,] 1180 1220 1260
[1] 2 3
[,1] [,2] [,3] [,4]
a 495 555 615 675
b 515 575 635 695
c 535 595 655 715
[1] 2 4
V5 V6 V7 V8 V9
a 84 276 468 660 852
b 100 292 484 676 868
c 116 308 500 692 884
[1] 1 3
[,1] [,2] [,3] [,4]
[1,] 765 855 945 1035
[2,] 780 870 960 1050
[1] 2 3 4
, , V5
[,1] [,2] [,3] [,4]
a 3 15 27 39
b 7 19 31 43
c 11 23 35 47
, , V6
[,1] [,2] [,3] [,4]
a 51 63 75 87
b 55 67 79 91
c 59 71 83 95
, , V7
[,1] [,2] [,3] [,4]
a 99 111 123 135
b 103 115 127 139
c 107 119 131 143
, , V8
[,1] [,2] [,3] [,4]
a 147 159 171 183
b 151 163 175 187
c 155 167 179 191
, , V9
[,1] [,2] [,3] [,4]
a 195 207 219 231
b 199 211 223 235
c 203 215 227 239
[1] 1 2 3
, , 1
a b c
[1,] 245 255 265
[2,] 250 260 270
, , 2
a b c
[1,] 275 285 295
[2,] 280 290 300
, , 3
a b c
[1,] 305 315 325
[2,] 310 320 330
, , 4
a b c
[1,] 335 345 355
[2,] 340 350 360
[1] 1 2 3 4
, , 1, V5
a b c
[1,] 1 3 5
[2,] 2 4 6
, , 2, V5
a b c
[1,] 7 9 11
[2,] 8 10 12
, , 3, V5
a b c
[1,] 13 15 17
[2,] 14 16 18
, , 4, V5
a b c
[1,] 19 21 23
[2,] 20 22 24
, , 1, V6
a b c
[1,] 25 27 29
[2,] 26 28 30
, , 2, V6
a b c
[1,] 31 33 35
[2,] 32 34 36
, , 3, V6
a b c
[1,] 37 39 41
[2,] 38 40 42
, , 4, V6
a b c
[1,] 43 45 47
[2,] 44 46 48
, , 1, V7
a b c
[1,] 49 51 53
[2,] 50 52 54
, , 2, V7
a b c
[1,] 55 57 59
[2,] 56 58 60
, , 3, V7
a b c
[1,] 61 63 65
[2,] 62 64 66
, , 4, V7
a b c
[1,] 67 69 71
[2,] 68 70 72
, , 1, V8
a b c
[1,] 73 75 77
[2,] 74 76 78
, , 2, V8
a b c
[1,] 79 81 83
[2,] 80 82 84
, , 3, V8
a b c
[1,] 85 87 89
[2,] 86 88 90
, , 4, V8
a b c
[1,] 91 93 95
[2,] 92 94 96
, , 1, V9
a b c
[1,] 97 99 101
[2,] 98 100 102
, , 2, V9
a b c
[1,] 103 105 107
[2,] 104 106 108
, , 3, V9
a b c
[1,] 109 111 113
[2,] 110 112 114
, , 4, V9
a b c
[1,] 115 117 119
[2,] 116 118 120
> for(m in marg) ## 75% of the time here was spent on the names
+ print(dim(apply(arr, print(m), quantile, names=FALSE)) == c(5,d.arr[m]))
[1] 1 2
[1] TRUE TRUE TRUE
[1] 2 3
[1] TRUE TRUE TRUE
[1] 2 4
[1] TRUE TRUE TRUE
[1] 1 3
[1] TRUE TRUE TRUE
[1] 2 3 4
[1] TRUE TRUE TRUE TRUE
[1] 1 2 3
[1] TRUE TRUE TRUE TRUE
[1] 1 2 3 4
[1] TRUE TRUE TRUE TRUE TRUE
>
> ## Bessel
> nus <- c(0:5,10,20)
>
> x0 <- 2^(-20:10)
> plot(x0,x0, log='xy', ylab="", ylim=c(.1,1e60),type='n',
+ main = "Bessel Functions -Y_nu(x) near 0\n log - log scale")
> for(nu in sort(c(nus,nus+.5))) lines(x0, -besselY(x0,nu=nu), col = nu+2)
> legend(3,1e50, leg=paste("nu=", paste(nus,nus+.5, sep=",")), col=nus+2, lwd=1)
>
> x <- seq(3,500);yl <- c(-.3, .2)
> plot(x,x, ylim = yl, ylab="",type='n', main = "Bessel Functions Y_nu(x)")
> for(nu in nus){xx <- x[x > .6*nu]; lines(xx,besselY(xx,nu=nu), col = nu+2)}
> legend(300,-.08, leg=paste("nu=",nus), col = nus+2, lwd=1)
>
> x <- seq(10,50000,by=10);yl <- c(-.1, .1)
> plot(x,x, ylim = yl, ylab="",type='n', main = "Bessel Functions Y_nu(x)")
> for(nu in nus){xx <- x[x > .6*nu]; lines(xx,besselY(xx,nu=nu), col = nu+2)}
> summary(bY <- besselY(2,nu = nu <- seq(0,100,len=501)))
Min. 1st Qu. Median Mean 3rd Qu. Max.
-3.001e+155 -1.067e+107 -1.976e+62 -9.961e+152 -2.059e+23 1.000e+00
> which(bY >= 0)
[1] 1 2 3 4 5
> summary(bY <- besselY(2,nu = nu <- seq(3,300,len=51)))
Min. 1st Qu. Median Mean 3rd Qu. Max.
-Inf -Inf -2.248e+263 -Inf -3.777e+116 -1.000e+00
There were 22 warnings (use warnings() to see them)
> summary(bI <- besselI(x = x <- 10:700, 1))
Min. 1st Qu. Median Mean 3rd Qu. Max.
2.671e+03 6.026e+77 3.161e+152 3.501e+299 2.409e+227 1.529e+302
> ## end of moved from Bessel.Rd
>
> ## data.frame
> set.seed(123)
> L3 <- LETTERS[1:3]
> d <- data.frame(cbind(x=1, y=1:10), fac = sample(L3, 10, replace=TRUE))
> str(d)
'data.frame': 10 obs. of 3 variables:
$ x : num 1 1 1 1 1 1 1 1 1 1
$ y : num 1 2 3 4 5 6 7 8 9 10
$ fac: Factor w/ 3 levels "A","B","C": 1 3 2 3 3 1 2 3 2 2
> (d0 <- d[, FALSE]) # NULL dataframe with 10 rows
data frame with 0 columns and 10 rows
> (d.0 <- d[FALSE, ]) # <0 rows> dataframe (3 cols)
[1] x y fac
<0 rows> (or 0-length row.names)
> (d00 <- d0[FALSE,]) # NULL dataframe with 0 rows
data frame with 0 columns and 0 rows
> stopifnot(identical(d, cbind(d, d0)),
+ identical(d, cbind(d0, d)))
> stopifnot(identical(d, rbind(d,d.0)),
+ identical(d, rbind(d.0,d)),
+ identical(d, rbind(d00,d)),
+ identical(d, rbind(d,d00)))
> ## Comments: failed before ver. 1.4.0
>
> ## diag
> diag(array(1:4, dim=5))
[,1] [,2] [,3] [,4] [,5]
[1,] 1 0 0 0 0
[2,] 0 2 0 0 0
[3,] 0 0 3 0 0
[4,] 0 0 0 4 0
[5,] 0 0 0 0 1
> ## test behaviour with 0 rows or columns
> diag(0)
<0 x 0 matrix>
> z <- matrix(0, 0, 4)
> diag(z)
numeric(0)
> diag(z) <- numeric(0)
> z
[,1] [,2] [,3] [,4]
> ## end of moved from diag.Rd
>
> ## format
> ## handling of quotes
> zz <- data.frame(a=I("abc"), b=I("def\"gh"))
> format(zz)
a b
1 abc def"gh
> ## " (E fontification)
>
> ## printing more than 16 is platform-dependent
> for(i in c(1:5,10,15,16)) cat(i,":\t",format(pi,digits=i),"\n")
1 : 3
2 : 3.1
3 : 3.14
4 : 3.142
5 : 3.1416
10 : 3.141592654
15 : 3.14159265358979
16 : 3.141592653589793
>
> p <- c(47,13,2,.1,.023,.0045, 1e-100)/1000
> format.pval(p)
[1] "0.0470" "0.0130" "0.0020" "0.0001" "2.3e-05" "4.5e-06" "< 2e-16"
> format.pval(p / 0.9)
[1] "0.05222222" "0.01444444" "0.00222222" "0.00011111" "2.5556e-05"
[6] "5.0000e-06" "< 2.22e-16"
> format.pval(p / 0.9, dig=3)
[1] "0.052222" "0.014444" "0.002222" "0.000111" "2.56e-05" "5.00e-06" "< 2e-16"
> ## end of moved from format.Rd
>
>
> ## is.finite
> x <- c(100,-1e-13,Inf,-Inf, NaN, pi, NA)
> x # 1.000000 -3.000000 Inf -Inf NA 3.141593 NA
[1] 1.000000e+02 -1.000000e-13 Inf -Inf NaN
[6] 3.141593e+00 NA
> names(x) <- formatC(x, dig=3)
> is.finite(x)
100 -1e-13 Inf -Inf NaN 3.14 NA
TRUE TRUE FALSE FALSE FALSE TRUE FALSE
> ##- 100 -1e-13 Inf -Inf NaN 3.14 NA
> ##- T T . . . T .
> is.na(x)
100 -1e-13 Inf -Inf NaN 3.14 NA
FALSE FALSE FALSE FALSE TRUE FALSE TRUE
> ##- 100 -1e-13 Inf -Inf NaN 3.14 NA
> ##- . . . . T . T
> which(is.na(x) & !is.nan(x))# only 'NA': 7
NA
7
>
> is.na(x) | is.finite(x)
100 -1e-13 Inf -Inf NaN 3.14 NA
TRUE TRUE FALSE FALSE TRUE TRUE TRUE
> ##- 100 -1e-13 Inf -Inf NaN 3.14 NA
> ##- T T . . T T T
> is.infinite(x)
100 -1e-13 Inf -Inf NaN 3.14 NA
FALSE FALSE TRUE TRUE FALSE FALSE FALSE
> ##- 100 -1e-13 Inf -Inf NaN 3.14 NA
> ##- . . T T . . .
>
> ##-- either finite or infinite or NA:
> all(is.na(x) != is.finite(x) | is.infinite(x)) # TRUE
[1] TRUE
> all(is.nan(x) != is.finite(x) | is.infinite(x)) # FALSE: have 'real' NA
[1] FALSE
>
> ##--- Integer
> (ix <- structure(as.integer(x),names= names(x)))
100 -1e-13 Inf -Inf NaN 3.14 NA
100 0 NA NA NA 3 NA
Warning message:
In structure(as.integer(x), names = names(x)) :
NAs introduced by coercion to integer range
> ##- 100 -1e-13 Inf -Inf NaN 3.14 NA
> ##- 100 0 NA NA NA 3 NA
> all(is.na(ix) != is.finite(ix) | is.infinite(ix)) # TRUE (still)
[1] TRUE
>
> storage.mode(ii <- -3:5)
[1] "integer"
> storage.mode(zm <- outer(ii,ii, FUN="*"))# integer
[1] "double"
> storage.mode(zd <- outer(ii,ii, FUN="/"))# double
[1] "double"
> range(zd, na.rm=TRUE)# -Inf Inf
[1] -Inf Inf
> zd[,ii==0]
[1] -Inf -Inf -Inf NaN Inf Inf Inf Inf Inf
>
> (storage.mode(print(1:1 / 0:0)))# Inf "double"
[1] Inf
[1] "double"
> (storage.mode(print(1:1 / 1:1)))# 1 "double"
[1] 1
[1] "double"
> (storage.mode(print(1:1 + 1:1)))# 2 "integer"
[1] 2
[1] "integer"
> (storage.mode(print(2:2 * 2:2)))# 4 "integer"
[1] 4
[1] "integer"
> ## end of moved from is.finite.Rd
>
>
> ## kronecker
> fred <- matrix(1:12, 3, 4, dimnames=list(LETTERS[1:3], LETTERS[4:7]))
> bill <- c("happy" = 100, "sad" = 1000)
> kronecker(fred, bill, make.dimnames = TRUE)
D: E: F: G:
A:happy 100 400 700 1000
A:sad 1000 4000 7000 10000
B:happy 200 500 800 1100
B:sad 2000 5000 8000 11000
C:happy 300 600 900 1200
C:sad 3000 6000 9000 12000
>
> bill <- outer(bill, c("cat"=3, "dog"=4))
> kronecker(fred, bill, make.dimnames = TRUE)
D:cat D:dog E:cat E:dog F:cat F:dog G:cat G:dog
A:happy 300 400 1200 1600 2100 2800 3000 4000
A:sad 3000 4000 12000 16000 21000 28000 30000 40000
B:happy 600 800 1500 2000 2400 3200 3300 4400
B:sad 6000 8000 15000 20000 24000 32000 33000 44000
C:happy 900 1200 1800 2400 2700 3600 3600 4800
C:sad 9000 12000 18000 24000 27000 36000 36000 48000
>
> # dimnames are hard work: let's test them thoroughly
>
> dimnames(bill) <- NULL
> kronecker(fred, bill, make=TRUE)
D: D: E: E: F: F: G: G:
A: 300 400 1200 1600 2100 2800 3000 4000
A: 3000 4000 12000 16000 21000 28000 30000 40000
B: 600 800 1500 2000 2400 3200 3300 4400
B: 6000 8000 15000 20000 24000 32000 33000 44000
C: 900 1200 1800 2400 2700 3600 3600 4800
C: 9000 12000 18000 24000 27000 36000 36000 48000
> kronecker(bill, fred, make=TRUE)
:D :E :F :G :D :E :F :G
:A 300 1200 2100 3000 400 1600 2800 4000
:B 600 1500 2400 3300 800 2000 3200 4400
:C 900 1800 2700 3600 1200 2400 3600 4800
:A 3000 12000 21000 30000 4000 16000 28000 40000
:B 6000 15000 24000 33000 8000 20000 32000 44000
:C 9000 18000 27000 36000 12000 24000 36000 48000
>
> dim(bill) <- c(2, 2, 1)
> dimnames(bill) <- list(c("happy", "sad"), NULL, "")
> kronecker(fred, bill, make=TRUE)
, , :
D: D: E: E: F: F: G: G:
A:happy 300 400 1200 1600 2100 2800 3000 4000
A:sad 3000 4000 12000 16000 21000 28000 30000 40000
B:happy 600 800 1500 2000 2400 3200 3300 4400
B:sad 6000 8000 15000 20000 24000 32000 33000 44000
C:happy 900 1200 1800 2400 2700 3600 3600 4800
C:sad 9000 12000 18000 24000 27000 36000 36000 48000
>
> bill <- array(1:24, c(3, 4, 2))
> dimnames(bill) <- list(NULL, NULL, c("happy", "sad"))
> kronecker(bill, fred, make=TRUE)
, , happy:
:D :E :F :G :D :E :F :G :D :E :F :G :D :E :F :G
:A 1 4 7 10 4 16 28 40 7 28 49 70 10 40 70 100
:B 2 5 8 11 8 20 32 44 14 35 56 77 20 50 80 110
:C 3 6 9 12 12 24 36 48 21 42 63 84 30 60 90 120
:A 2 8 14 20 5 20 35 50 8 32 56 80 11 44 77 110
:B 4 10 16 22 10 25 40 55 16 40 64 88 22 55 88 121
:C 6 12 18 24 15 30 45 60 24 48 72 96 33 66 99 132
:A 3 12 21 30 6 24 42 60 9 36 63 90 12 48 84 120
:B 6 15 24 33 12 30 48 66 18 45 72 99 24 60 96 132
:C 9 18 27 36 18 36 54 72 27 54 81 108 36 72 108 144
, , sad:
:D :E :F :G :D :E :F :G :D :E :F :G :D :E :F :G
:A 13 52 91 130 16 64 112 160 19 76 133 190 22 88 154 220
:B 26 65 104 143 32 80 128 176 38 95 152 209 44 110 176 242
:C 39 78 117 156 48 96 144 192 57 114 171 228 66 132 198 264
:A 14 56 98 140 17 68 119 170 20 80 140 200 23 92 161 230
:B 28 70 112 154 34 85 136 187 40 100 160 220 46 115 184 253
:C 42 84 126 168 51 102 153 204 60 120 180 240 69 138 207 276
:A 15 60 105 150 18 72 126 180 21 84 147 210 24 96 168 240
:B 30 75 120 165 36 90 144 198 42 105 168 231 48 120 192 264
:C 45 90 135 180 54 108 162 216 63 126 189 252 72 144 216 288
> kronecker(fred, bill, make=TRUE)
, , :happy
D: D: D: D: E: E: E: E: F: F: F: F: G: G: G: G:
A: 1 4 7 10 4 16 28 40 7 28 49 70 10 40 70 100
A: 2 5 8 11 8 20 32 44 14 35 56 77 20 50 80 110
A: 3 6 9 12 12 24 36 48 21 42 63 84 30 60 90 120
B: 2 8 14 20 5 20 35 50 8 32 56 80 11 44 77 110
B: 4 10 16 22 10 25 40 55 16 40 64 88 22 55 88 121
B: 6 12 18 24 15 30 45 60 24 48 72 96 33 66 99 132
C: 3 12 21 30 6 24 42 60 9 36 63 90 12 48 84 120
C: 6 15 24 33 12 30 48 66 18 45 72 99 24 60 96 132
C: 9 18 27 36 18 36 54 72 27 54 81 108 36 72 108 144
, , :sad
D: D: D: D: E: E: E: E: F: F: F: F: G: G: G: G:
A: 13 16 19 22 52 64 76 88 91 112 133 154 130 160 190 220
A: 14 17 20 23 56 68 80 92 98 119 140 161 140 170 200 230
A: 15 18 21 24 60 72 84 96 105 126 147 168 150 180 210 240
B: 26 32 38 44 65 80 95 110 104 128 152 176 143 176 209 242
B: 28 34 40 46 70 85 100 115 112 136 160 184 154 187 220 253
B: 30 36 42 48 75 90 105 120 120 144 168 192 165 198 231 264
C: 39 48 57 66 78 96 114 132 117 144 171 198 156 192 228 264
C: 42 51 60 69 84 102 120 138 126 153 180 207 168 204 240 276
C: 45 54 63 72 90 108 126 144 135 162 189 216 180 216 252 288
>
> fred <- outer(fred, c("frequentist"=4, "bayesian"=4000))
> kronecker(fred, bill, make=TRUE)
, , frequentist:happy
D: D: D: D: E: E: E: E: F: F: F: F: G: G: G: G:
A: 4 16 28 40 16 64 112 160 28 112 196 280 40 160 280 400
A: 8 20 32 44 32 80 128 176 56 140 224 308 80 200 320 440
A: 12 24 36 48 48 96 144 192 84 168 252 336 120 240 360 480
B: 8 32 56 80 20 80 140 200 32 128 224 320 44 176 308 440
B: 16 40 64 88 40 100 160 220 64 160 256 352 88 220 352 484
B: 24 48 72 96 60 120 180 240 96 192 288 384 132 264 396 528
C: 12 48 84 120 24 96 168 240 36 144 252 360 48 192 336 480
C: 24 60 96 132 48 120 192 264 72 180 288 396 96 240 384 528
C: 36 72 108 144 72 144 216 288 108 216 324 432 144 288 432 576
, , frequentist:sad
D: D: D: D: E: E: E: E: F: F: F: F: G: G: G: G:
A: 52 64 76 88 208 256 304 352 364 448 532 616 520 640 760 880
A: 56 68 80 92 224 272 320 368 392 476 560 644 560 680 800 920
A: 60 72 84 96 240 288 336 384 420 504 588 672 600 720 840 960
B: 104 128 152 176 260 320 380 440 416 512 608 704 572 704 836 968
B: 112 136 160 184 280 340 400 460 448 544 640 736 616 748 880 1012
B: 120 144 168 192 300 360 420 480 480 576 672 768 660 792 924 1056
C: 156 192 228 264 312 384 456 528 468 576 684 792 624 768 912 1056
C: 168 204 240 276 336 408 480 552 504 612 720 828 672 816 960 1104
C: 180 216 252 288 360 432 504 576 540 648 756 864 720 864 1008 1152
, , bayesian:happy
D: D: D: D: E: E: E: E: F: F: F:
A: 4000 16000 28000 40000 16000 64000 112000 160000 28000 112000 196000
A: 8000 20000 32000 44000 32000 80000 128000 176000 56000 140000 224000
A: 12000 24000 36000 48000 48000 96000 144000 192000 84000 168000 252000
B: 8000 32000 56000 80000 20000 80000 140000 200000 32000 128000 224000
B: 16000 40000 64000 88000 40000 100000 160000 220000 64000 160000 256000
B: 24000 48000 72000 96000 60000 120000 180000 240000 96000 192000 288000
C: 12000 48000 84000 120000 24000 96000 168000 240000 36000 144000 252000
C: 24000 60000 96000 132000 48000 120000 192000 264000 72000 180000 288000
C: 36000 72000 108000 144000 72000 144000 216000 288000 108000 216000 324000
F: G: G: G: G:
A: 280000 40000 160000 280000 400000
A: 308000 80000 200000 320000 440000
A: 336000 120000 240000 360000 480000
B: 320000 44000 176000 308000 440000
B: 352000 88000 220000 352000 484000
B: 384000 132000 264000 396000 528000
C: 360000 48000 192000 336000 480000
C: 396000 96000 240000 384000 528000
C: 432000 144000 288000 432000 576000
, , bayesian:sad
D: D: D: D: E: E: E: E: F: F: F:
A: 52000 64000 76000 88000 208000 256000 304000 352000 364000 448000 532000
A: 56000 68000 80000 92000 224000 272000 320000 368000 392000 476000 560000
A: 60000 72000 84000 96000 240000 288000 336000 384000 420000 504000 588000
B: 104000 128000 152000 176000 260000 320000 380000 440000 416000 512000 608000
B: 112000 136000 160000 184000 280000 340000 400000 460000 448000 544000 640000
B: 120000 144000 168000 192000 300000 360000 420000 480000 480000 576000 672000
C: 156000 192000 228000 264000 312000 384000 456000 528000 468000 576000 684000
C: 168000 204000 240000 276000 336000 408000 480000 552000 504000 612000 720000
C: 180000 216000 252000 288000 360000 432000 504000 576000 540000 648000 756000
F: G: G: G: G:
A: 616000 520000 640000 760000 880000
A: 644000 560000 680000 800000 920000
A: 672000 600000 720000 840000 960000
B: 704000 572000 704000 836000 968000
B: 736000 616000 748000 880000 1012000
B: 768000 660000 792000 924000 1056000
C: 792000 624000 768000 912000 1056000
C: 828000 672000 816000 960000 1104000
C: 864000 720000 864000 1008000 1152000
> ## end of moved from kronecker.Rd
>
> ## merge
> authors <- data.frame(
+ surname = c("Tukey", "Venables", "Tierney", "Ripley", "McNeil"),
+ nationality = c("US", "Australia", "US", "UK", "Australia"),
+ deceased = c("yes", rep("no", 4)))
> books <- data.frame(
+ name = c("Tukey", "Venables", "Tierney",
+ "Ripley", "Ripley", "McNeil", "R Core"),
+ title = c("Exploratory Data Analysis",
+ "Modern Applied Statistics ...",
+ "LISP-STAT",
+ "Spatial Statistics", "Stochastic Simulation",
+ "Interactive Data Analysis",
+ "An Introduction to R"),
+ other.author = c(NA, "Ripley", NA, NA, NA, NA,
+ "Venables & Smith"))
> b2 <- books; names(b2)[1] <- names(authors)[1]
>
> merge(authors, b2, all.x = TRUE)
surname nationality deceased title other.author
1 McNeil Australia no Interactive Data Analysis <NA>
2 Ripley UK no Spatial Statistics <NA>
3 Ripley UK no Stochastic Simulation <NA>
4 Tierney US no LISP-STAT <NA>
5 Tukey US yes Exploratory Data Analysis <NA>
6 Venables Australia no Modern Applied Statistics ... Ripley
> merge(authors, b2, all.y = TRUE)
surname nationality deceased title other.author
1 McNeil Australia no Interactive Data Analysis <NA>
2 Ripley UK no Spatial Statistics <NA>
3 Ripley UK no Stochastic Simulation <NA>
4 Tierney US no LISP-STAT <NA>
5 Tukey US yes Exploratory Data Analysis <NA>
6 Venables Australia no Modern Applied Statistics ... Ripley
7 R Core <NA> <NA> An Introduction to R Venables & Smith
>
> ## empty d.f. :
> merge(authors, b2[7,])
[1] surname nationality deceased title other.author
<0 rows> (or 0-length row.names)
>
> merge(authors, b2[7,], all.y = TRUE)
surname nationality deceased title other.author
1 R Core <NA> <NA> An Introduction to R Venables & Smith
> merge(authors, b2[7,], all.x = TRUE)
surname nationality deceased title other.author
1 McNeil Australia no <NA> <NA>
2 Ripley UK no <NA> <NA>
3 Tierney US no <NA> <NA>
4 Tukey US yes <NA> <NA>
5 Venables Australia no <NA> <NA>
> ## end of moved from merge.Rd
>
> ## NA
> is.na(c(1,NA))
[1] FALSE TRUE
> is.na(paste(c(1,NA)))
[1] FALSE FALSE
> is.na(list())# logical(0)
logical(0)
> ll <- list(pi,"C",NaN,Inf, 1:3, c(0,NA), NA)
> is.na (ll)
[1] FALSE FALSE TRUE FALSE FALSE FALSE TRUE
> lapply(ll, is.nan) # is.nan no longer works on lists
[[1]]
[1] FALSE
[[2]]
[1] FALSE
[[3]]
[1] TRUE
[[4]]
[1] FALSE
[[5]]
[1] FALSE FALSE FALSE
[[6]]
[1] FALSE FALSE
[[7]]
[1] FALSE
> ## end of moved from NA.Rd
>
> ## is.na was returning unset values on nested lists
> ll <- list(list(1))
> for (i in 1:5) print(as.integer(is.na(ll)))
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
>
> ## scale
> ## test out NA handling
> tm <- matrix(c(2,1,0,1,0,NA,NA,NA,0), nrow=3)
> scale(tm, , FALSE)
[,1] [,2] [,3]
[1,] 1 0.5 NA
[2,] 0 -0.5 NA
[3,] -1 NA 0
attr(,"scaled:center")
[1] 1.0 0.5 0.0
> scale(tm)
[,1] [,2] [,3]
[1,] 1 0.7071068 NA
[2,] 0 -0.7071068 NA
[3,] -1 NA NaN
attr(,"scaled:center")
[1] 1.0 0.5 0.0
attr(,"scaled:scale")
[1] 1.0000000 0.7071068 0.0000000
> ## end of moved from scale.Rd
>
> ## tabulate
> tabulate(numeric(0))
[1] 0
> ## end of moved from tabulate.Rd
>
> ## ts
> # Ensure working arithmetic for `ts' objects :
> stopifnot(z == z)
> stopifnot(z-z == 0)
>
> ts(1:5, start=2, end=4) # truncate
Time Series:
Start = 2
End = 4
Frequency = 1
[1] 1 2 3
> ts(1:5, start=3, end=17)# repeat
Time Series:
Start = 3
End = 17
Frequency = 1
[1] 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
> ## end of moved from ts.Rd
>
> ### end of moved
>
>
> ## PR 715 (Printing list elements w/attributes)
> ##
> l <- list(a=10)
> attr(l$a, "xx") <- 23
> l
$a
[1] 10
attr(,"xx")
[1] 23
> ## Comments:
> ## should print as
> # $a:
> # [1] 10
> # attr($a, "xx"):
> # [1] 23
>
> ## On the other hand
> m <- matrix(c(1, 2, 3, 0, 10, NA), 3, 2)
> na.omit(m)
[,1] [,2]
[1,] 1 0
[2,] 2 10
attr(,"na.action")
[1] 3
attr(,"class")
[1] "omit"
> ## should print as
> # [,1] [,2]
> # [1,] 1 0
> # [2,] 2 10
> # attr(,"na.action")
> # [1] 3
> # attr(,"na.action")
> # [1] "omit"
>
> ## and
> x <- 1
> attr(x, "foo") <- list(a="a")
> x
[1] 1
attr(,"foo")
attr(,"foo")$a
[1] "a"
> ## should print as
> # [1] 1
> # attr(,"foo")
> # attr(,"foo")$a
> # [1] "a"
>
>
> ## PR 746 (printing of lists)
> ##
> test.list <- list(A = list(formula=Y~X, subset=TRUE),
+ B = list(formula=Y~X, subset=TRUE))
>
> test.list
$A
$A$formula
Y ~ X
$A$subset
[1] TRUE
$B
$B$formula
Y ~ X
$B$subset
[1] TRUE
> ## Comments:
> ## should print as
> # $A
> # $A$formula
> # Y ~ X
> #
> # $A$subset
> # [1] TRUE
> #
> #
> # $B
> # $B$formula
> # Y ~ X
> #
> # $B$subset
> # [1] TRUE
>
> ## Marc Feldesman 2001-Feb-01. Precision in summary.data.frame & *.matrix
> summary(attenu)
event mag station dist
Min. : 1.00 Min. :5.000 117 : 5 Min. : 0.50
1st Qu.: 9.00 1st Qu.:5.300 1028 : 4 1st Qu.: 11.32
Median :18.00 Median :6.100 113 : 4 Median : 23.40
Mean :14.74 Mean :6.084 112 : 3 Mean : 45.60
3rd Qu.:20.00 3rd Qu.:6.600 135 : 3 3rd Qu.: 47.55
Max. :23.00 Max. :7.700 (Other):147 Max. :370.00
NA's : 16
accel
Min. :0.00300
1st Qu.:0.04425
Median :0.11300
Mean :0.15422
3rd Qu.:0.21925
Max. :0.81000
> summary(attenu, digits = 5)
event mag station dist
Min. : 1.000 Min. :5.0000 117 : 5 Min. : 0.500
1st Qu.: 9.000 1st Qu.:5.3000 1028 : 4 1st Qu.: 11.325
Median :18.000 Median :6.1000 113 : 4 Median : 23.400
Mean :14.742 Mean :6.0841 112 : 3 Mean : 45.603
3rd Qu.:20.000 3rd Qu.:6.6000 135 : 3 3rd Qu.: 47.550
Max. :23.000 Max. :7.7000 (Other):147 Max. :370.000
NA's : 16
accel
Min. :0.00300
1st Qu.:0.04425
Median :0.11300
Mean :0.15422
3rd Qu.:0.21925
Max. :0.81000
> summary(data.matrix(attenu), digits = 5)# the same for matrix
event mag station dist
Min. : 1.000 Min. :5.0000 Min. : 1.000 Min. : 0.500
1st Qu.: 9.000 1st Qu.:5.3000 1st Qu.: 24.250 1st Qu.: 11.325
Median :18.000 Median :6.1000 Median : 56.500 Median : 23.400
Mean :14.742 Mean :6.0841 Mean : 56.928 Mean : 45.603
3rd Qu.:20.000 3rd Qu.:6.6000 3rd Qu.: 86.750 3rd Qu.: 47.550
Max. :23.000 Max. :7.7000 Max. :117.000 Max. :370.000
NA's :16
accel
Min. :0.00300
1st Qu.:0.04425
Median :0.11300
Mean :0.15422
3rd Qu.:0.21925
Max. :0.81000
> ## Comments:
> ## No difference between these in 1.2.1 and earlier
> set.seed(1)
> x <- c(round(runif(10), 2), 10000)
> summary(x)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.060 0.320 0.630 909.600 0.905 10000.000
> summary(data.frame(x))
x
Min. : 0.060
1st Qu.: 0.320
Median : 0.630
Mean : 909.592
3rd Qu.: 0.905
Max. :10000.000
> ## Comments:
> ## All entries show all 3 digits after the decimal point now.
>
> ## Chong Gu 2001-Feb-16. step on binomials
> detg1 <-
+ structure(list(Temp = structure(c(2L, 1L, 2L, 1L, 2L, 1L, 2L,
+ 1L, 2L, 1L, 2L, 1L), .Label = c("High", "Low"), class = "factor"),
+ M.user = structure(c(1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
+ 1L, 2L, 2L), .Label = c("N", "Y"), class = "factor"),
+ Soft = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L),
+ .Label = c("Hard", "Medium", "Soft"), class = "factor"),