Running S OLD ...
> prefix("apply.")	# test of apply and multivariate stuff, some time-series
> $Random.seed_c(57,0,3,0,0,0,49,16,0,0,0,0)	# to initialize at same spot
> matr_matrix(rnorm(100),20,5)
> print(cm_apply(matr,2,"mean")); apply(matr,2,"var")
       0.1945514   -0.04351466  -0.05409370   0.2684494   -0.2280429
      1.315903  0.881393  1.389505  1.046788  0.792241
> 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
      3.222376e-6
> split(matr,floor(matr))->str
> str_sapply(str,"sort")	# groups for each integer
> if(all(c(str)==sort(matr)))"C works with structures"
      "C works with structures"
> ncomp(str);compname(str)
       7
      "-4"  "-3"  "-2"  "-1"  " 0"  "1"   "2"
> diff(seq(10)^2)	# first differences
        3    5    7    9   11   13   15   17   19
> diff(seq(10)^2,diff=2)	# second
       2   2   2   2   2   2   2   2
> ttt_ts(1:10,1953,4)
> tsmatrix(ttt,lag(ttt,3),lag(ttt,-1))

Array:
6 by 3

Time-series:
start: 1953 2   end: 1954 3   Quarterly

       [,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

> window(ttt,c(1953,2),c(1954,4))

Time-series:
start: 1953 2   end: 1954 4   Quarterly

         1Q   2Q   3Q   4Q
 1953          2    3    4
 1954     5    6    7    8

> ary_array(1:18,c(2,3,3))
> ary; aperm(ary,3:1)	# permute the 3-way array

Array:
2 by 3 by 3

[,,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



Array:
3 by 3 by 2

[,,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

Array:
4 by 1

       [,1]
[1,]      4
[2,]      3
[3,]      2
[4,]      1

> rmat_matrix(rnorm(60),20,3); ry_rnorm(20)
> leaps(rmat,ry,names=c("a","b","c"))

 $Cp
      0.0317459  0.3711910  0.3768845  2.006849   2.026376   2.370882
[7]   4.000000
 $size
       2   2   2   3   3   3   4
 $label
      "c"    "b"    "a"    "bc"   "ac"   "ab"   "abc"
 $which
Array:
7 by 3

       [,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
      -0.1026149  -0.1213732  -0.2081390   0.1170755
 $resid
       -1.287198   -0.4802884   0.2404126   0.0        -1.035471   -0.5790480
[ 7]    0.3491124   0.0        -0.7902446   0.0989412   0.0        -0.1979147
[13]    0.2278315   0.0        -1.230182    0.7375273   1.012247   -0.5687742
[19]    0.2329916   1.751515
> smat_scale(rmat[order(runif(len(rmat)))[1:2]]_NA)	# sprinkle 2 NAs through rmat
> apply(smat,2,"mean")	# should be zero
      -4.901698e-9  1.490116e-8   2.048910e-9
> apply(smat,2,"var")	# should be 1
Error: Missing values not allowed
Error in var: argument x
Error in apply
Dumped
> loglin(seq(5) %o seq(6),c(1,0,2))	# fit should be perfect (table of products)
2 iterations: deviation  0

Array:
5 by 6

       [,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
Array:
19 by 2

        [,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
       0.1329451  0.2896009  0.5267324  0.5831050  0.6229567  0.7934617
[ 7]   1.003630   1.054631   1.237521   1.387318   1.391106   1.514094
[13]   1.527812   1.849985   1.917332   2.106776   2.381410   2.769629
[19]   3.205298
 $order
        5  12  16   4   7   8  17  20  11   3  14  13   9  15   2  10   1  18
[19]    6  19
> cutree(h,3)	# make 3 groups

 $Data
        2   2   2   1   1   2   1   3   2   2   2   1   2   2   2   1   2   2
[19]    2   2
 $height
      2.381411  2.106776  0.0
> subtree(h,c(1,4))	# subtree with individuals 1 and 4

 $merge
Array:
19 by 2

        [,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
       0.1329451  0.2896009  0.5267324  0.5831050  0.6229567  0.7934617
[ 7]   1.003630   1.054631   1.237521   1.387318   1.391106   1.514094
[13]   1.527812   1.849985   1.917332   2.106776   2.381410   2.769629
[19]   3.205298
 $order
        5  12  16   4   7   8  17  20  11   3  14  13   9  15   2  10   1  18
[19]    6  19
2.3u 1.3s 6r 	 /usr/s/cmd/RUN.S
