options echo=2
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")
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
split(matr,floor(matr))->str
str_sapply(str,"sort")	# groups for each integer
if(all(c(str)==sort(matr)))"C works with structures"
ncomp(str);compname(str)
diff(seq(10)^2)	# first differences
diff(seq(10)^2,diff=2)	# second
ttt_ts(1:10,1953,4)
tsmatrix(ttt,lag(ttt,3),lag(ttt,-1))
window(ttt,c(1953,2),c(1954,4))
ary_array(1:18,c(2,3,3))
ary; aperm(ary,3:1)	# permute the 3-way array
solve(diag(4),4:1)	# should be 4:1
rmat_matrix(rnorm(60),20,3); ry_rnorm(20)
leaps(rmat,ry,names=c("a","b","c"))
l1fit(rmat,ry)
smat_scale(rmat[order(runif(len(rmat)))[1:2]]_NA)	# sprinkle 2 NAs through rmat
apply(smat,2,"mean")	# should be zero
apply(smat,2,"var")	# should be 1
loglin(seq(5) %o seq(6),c(1,0,2))	# fit should be perfect (table of products)
d_dist(rmat)	# generate a distance matrix
h_hclust(d,method="ave")	# cluster, average method
h
cutree(h,3)	# make 3 groups
subtree(h,c(1,4))	# subtree with individuals 1 and 4
