> .Random.seed <- c(57,0,3,0,0,0,49,16,0,0,0,0)
> matr_matrix(rnorm(100),20,5)
> print(cm_apply(matr,2,"mean"));
[1]  0.19455150 -0.04351468 -0.05409376  0.26844949 -0.22804293
> apply(matr,2,"var")
[1] 1.3159026 0.8813932 1.3895046 1.0467877 0.7922408
> rmat_sweep(matr,2,cm)	# get rid of col means
> resid_sweep(rmat,1,apply(rmat,1,"mean"))	# now row means
> two_twoway(matr,trim=0)
> sum(abs(two$resid-resid))	# should be small
[1] 3.298745e-06
> split(matr,floor(matr))->str
> str_sapply(str,"sort")	# groups for each integer
> all(unlist(str)==sort(matr))
[1] T
> ncomp(str);
[1] 7
> compname(str)
[1] "-4" "-3" "-2" "-1" " 0" "1"  "2" 
> diff(seq(10)^2)	# first differences
[1]  3  5  7  9 11 13 15 17 19
> diff(seq(10)^2,diff=2)	# second
[1] 2 2 2 2 2 2 2 2
> ttt_ts(1:10,1953,4)
> tsmatrix(ttt,lag(ttt,3),lag(ttt,-1))
     [,1] [,2] [,3] 
[1,]    2    5    1
[2,]    3    6    2
[3,]    4    7    3
[4,]    5    8    4
[5,]    6    9    5
[6,]    7   10    6
attr(, "tsp"):
[1] 1953.25 1954.50    4.00
> window(ttt,c(1953,2),c(1954,4))
      1Q 2Q 3Q 4Q
1953:     2  3  4
1954:  5  6  7  8
> ary_array(1:18,c(2,3,3))
> ary;

, , 1
     [,1] [,2] [,3] 
[1,]    1    3    5
[2,]    2    4    6

, , 2
     [,1] [,2] [,3] 
[1,]    7    9   11
[2,]    8   10   12

, , 3
     [,1] [,2] [,3] 
[1,]   13   15   17
[2,]   14   16   18
> aperm(ary,3:1)	# permute the 3-way array

, , 1
     [,1] [,2] [,3] 
[1,]    1    3    5
[2,]    7    9   11
[3,]   13   15   17

, , 2
     [,1] [,2] [,3] 
[1,]    2    4    6
[2,]    8   10   12
[3,]   14   16   18
> solve(diag(4),4:1)	# should be 4:1
[1] 4 3 2 1
> rmat_matrix(rnorm(60),20,3);
> ry_rnorm(20)
> leaps(rmat,ry,names=c("a","b","c"))
$Cp:
[1] 0.0317440 0.3711929 0.3768845 2.0068512 2.0263767 2.3708820 4.0000000

$size:
[1] 2 2 2 3 3 3 4

$label:
[1] "c"   "b"   "a"   "bc"  "ac"  "ab"  "abc"

$which:
     [,1] [,2] [,3] 
[1,]    F    F    T
[2,]    F    T    F
[3,]    T    F    F
[4,]    F    T    T
[5,]    T    F    T
[6,]    T    T    F
[7,]    T    T    T

> l1fit(rmat,ry)
$coef:
[1] -0.1026149 -0.1213732 -0.2081390  0.1170755

$resid:
 [1] -1.28719866 -0.48028857  0.24041253  0.00000000 -1.03547132 -0.57904851
 [7]  0.34911224  0.00000000 -0.79024476  0.09894118  0.00000000 -0.19791478
[13]  0.22783148  0.00000000 -1.23018229  0.73752725  1.01224756 -0.56877422
[19]  0.23299153  1.75151515

> rmat[order(runif(len(rmat)))[1:2]]_NA	# sprinkle 2 NAs through rmat
> smat_scale(rmat)
> apply(smat,2,"mean")	# should be zero
[1]            NA            NA -1.511337e-08
> apply(smat,2,"var")	# should be 1
Error in call to ".Fortran": subroutine dqrsl1: Missing values in argument 5
Dumped
> loglin(seq(5) %o% seq(6),c(1,0,2))	# fit should be perfect (table of products)
2 iterations: deviation  0
     [,1] [,2] [,3] [,4] [,5] [,6] 
[1,]    1    2    3    4    5    6
[2,]    2    4    6    8   10   12
[3,]    3    6    9   12   15   18
[4,]    4    8   12   16   20   24
[5,]    5   10   15   20   25   30
> d_dist(rmat)	# generate a distance matrix
> h_hclust(d,method="ave")	# cluster, average method
> h
$merge:
      [,1] [,2] 
 [1,]   -3  -14
 [2,]  -17  -20
 [3,]   -6  -19
 [4,]   -9  -15
 [5,]   -2  -10
 [6,]  -18    3
 [7,]   -1    6
 [8,]  -11    1
 [9,]   -5  -12
[10,]    5    7
[11,]    2    8
[12,]   -4   -7
[13,]    4   10
[14,]  -16   12
[15,]  -13   13
[16,]   11   15
[17,]    9   14
[18,]   -8   16
[19,]   17   18

$height:
 [1] 0.1329445 0.2896010 0.5267323 0.5831049 0.6229568 0.7934617 1.0036306
 [8] 1.0546312 1.2375207 1.3873187 1.3911070 1.5140948 1.5278130 1.8499851
[15] 1.9173328 2.1067765 2.3814108 2.7696297 3.2052982

$order:
 [1]  5 12 16  4  7  8 17 20 11  3 14 13  9 15  2 10  1 18  6 19

> cutree(h,3)	# make 3 groups
 [1] 2 2 2 1 1 2 1 3 2 2 2 1 2 2 2 1 2 2 2 2
attr(, "height"):
[1] 2.381411 2.106776 0.000000
> subtree(h,c(1,4))	# subtree with individuals 1 and 4
$merge:
      [,1] [,2] 
 [1,]   -3  -14
 [2,]  -17  -20
 [3,]   -6  -19
 [4,]   -9  -15
 [5,]   -2  -10
 [6,]  -18    3
 [7,]   -1    6
 [8,]  -11    1
 [9,]   -5  -12
[10,]    5    7
[11,]    2    8
[12,]   -4   -7
[13,]    4   10
[14,]  -16   12
[15,]  -13   13
[16,]   11   15
[17,]    9   14
[18,]   -8   16
[19,]   17   18

$height:
 [1] 0.1329445 0.2896010 0.5267323 0.5831049 0.6229568 0.7934617 1.0036306
 [8] 1.0546312 1.2375207 1.3873187 1.3911070 1.5140948 1.5278130 1.8499851
[15] 1.9173328 2.1067765 2.3814108 2.7696297 3.2052982

$order:
 [1]  5 12 16  4  7  8 17 20 11  3 14 13  9 15  2 10  1 18  6 19

> 12.1u 3.9s 56r 	 /usr/s/cmd/Sqpe
