Re: [R] Applying functions to partitions

2009-02-16 Thread Stavros Macrakis
On Mon, Feb 16, 2009 at 7:52 PM, Bert Gunter wrote: > I suppose the clean way to do this would be to define a cartesian product of > two factors with the induced lexicographic order (is there a standard > function for doing this?):" > > Of course. ?interaction. Perhaps my specification was unclea

Re: [R] Applying functions to partitions

2009-02-16 Thread Bert Gunter
"... I suppose the clean way to do this would be to define a cartesian product of two factors with the induced lexicographic order (is there a standard function for doing this?):" Of course. ?interaction. -- Bert Gunter Genentch __ R-help@r-project.

Re: [R] Applying functions to partitions

2009-02-16 Thread Stavros Macrakis
On Mon, Feb 16, 2009 at 4:23 PM, Martin Morgan wrote: > Stavros Macrakis writes: > >matrix(tapply(mm, outer(rfact,cfact,paste), mean), > > length(unique(rfact))) > > or the variant > > idx <- outer(rfact, (cfact - 1) * max(rfact), "+") > matrix(tapply(m, idx, mean), max(rfact

Re: [R] Applying functions to partitions

2009-02-16 Thread Martin Morgan
Stavros Macrakis writes: > Assuming your matrix is: > > mm <- matrix(runif(6*6),6,6) > > And your blocks are defined by integers or factors: > >cfact <- c(1,1,1,2,3,3) >rfact <- c(1,1,1,2,2,3) > > Then the following should do the trick: > >matrix(tapply(mm, outer(rfact,cfact,paste

Re: [R] Applying functions to partitions

2009-02-16 Thread David Winsemius
Its not clear that the object returned from such an operation would be a matrix, but if things remain very regular then perhapos you will succeed with this: > markmtx <- matrix(scan(textConnection("a a a d g g + a a a d g g + a a a d g g + b b b e h h + b b b e h h + c c c

Re: [R] Applying functions to partitions

2009-02-16 Thread Stavros Macrakis
Assuming your matrix is: mm <- matrix(runif(6*6),6,6) And your blocks are defined by integers or factors: cfact <- c(1,1,1,2,3,3) rfact <- c(1,1,1,2,2,3) Then the following should do the trick: matrix(tapply(mm, outer(rfact,cfact,paste), mean), length(unique(rfact)))

Re: [R] Applying functions to partitions

2009-02-16 Thread Charles C. Berry
On Mon, 16 Feb 2009, Titus von der Malsburg wrote: On Mon, Feb 16, 2009 at 01:45:52PM -0500, Stavros Macrakis wrote: How are the blocks defined? As a priori index ranges? By factors? By some property of i,j? Or...? Ok, I should have been more specific. The blocks are defined by factors. The

Re: [R] Applying functions to partitions

2009-02-16 Thread Titus von der Malsburg
On Mon, Feb 16, 2009 at 01:45:52PM -0500, Stavros Macrakis wrote: > How are the blocks defined? As a priori index ranges? By factors? By > some property of i,j? Or...? Ok, I should have been more specific. The blocks are defined by factors. There's a factor for the columns and a factor for the r

[R] Applying functions to partitions

2009-02-16 Thread Titus von der Malsburg
Hi list! I have a large matrix which I'd like to partition into blocks and for each block I'd like to compute the mean. Following a example where each letter marks a block of the partition: a a a d g g a a a d g g a a a d g g b b b e h h b b b e h h c c c f i i I