rc<-list(c(
123,321,234,543,654,768,986,987,246,284),c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"))

# the matrix has rownames that are used as identifiers and columns
# of time. 1 years worth of data. Thats the native format

 test<-matrix(seq(1,120, by=1), nrow=10,dimnames=rc)
 test
      Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
123   1  11  21  31  41  51  61  71  81  91 101 111
321   2  12  22  32  42  52  62  72  82  92 102 112
234   3  13  23  33  43  53  63  73  83  93 103 113
543   4  14  24  34  44  54  64  74  84  94 104 114
654   5  15  25  35  45  55  65  75  85  95 105 115
768   6  16  26  36  46  56  66  76  86  96 106 116
986   7  17  27  37  47  57  67  77  87  97 107 117
987   8  18  28  38  48  58  68  78  88  98 108 118
246   9  19  29  39  49  59  69  79  89  99 109 119
284  10  20  30  40  50  60  70  80  90 100 110 120

#The desired result would be a merged zoo object with the row names used as
the colnames of the multiple zoo series

test2<-matrix(test,nrow=12,  byrow=F)
g<-zoo(test2[,1],frequency=12)
 MYZOO <-merge(g,test2[,2:10])

# the result MYZOO is a zoo object, but we've lost the row names in the
transformation of the matrix

#So
colnames(MYZOO)<-row.names(test)

#Fixes that problem. Is there a more elegant way to do this???

# now this zoo object needs to be "swept" out of a much longer zoo object
# with the same column names.. The 'sweep' function is "-"

Sweep works normally by sweeping out a vector from an array (by column or by
row


sweep(x, MARGIN, STATS, FUN="-", check.margin=TRUE, ...)


 so in my example  x would be a  long yearmon zoo object with the same
column names
as MYZOO above, but decades of data. MARGIN would be rows and the STATS
to sweep out would be the values in MYZOO.


test3<-matrix(seq(1,720, by=1), ncol=10)
p<-zoo(test3[,1], freq=12)
longzoo<-merge(p,test3[,2:10])
colnames(longzoo)<-row.names(test)

what we want to do is to sweep out MYZOO from longzoo. I could just repeat
the data in MYZOO 6 times and then subtract MYZOO from longzoo, but thats
a potential memory buster in this situation

	[[alternative HTML version deleted]]

