I found a near solution  back further in r-sig-geo:
http://r-sig-geo.2731867.n2.nabble.com/combine-function-in-R-td7028762.html



with the addition of a line to join the attributes back to the
@attributes[[1]] it achieves the full equivalent of the combine in spatial
analyst:

r1 <- ratify(raster(matrix(c(5,5,6),3,3)),count=T)
r2<-ratify(raster(t(matrix(c(7,7,8),3,3))),count=T)
s<-stack(r1,r2)
names(s)<-c("r1","r2")
plot(s)
us <- unique(s)

uss <- apply(us, 1, function(x)paste(x, collapse='_'))
comb <- function(x) match(apply(x, 1, function(x)paste(x,
collapse='_')),uss)
r3 <- ratify(calc(s, comb))
r3@data@attributes[[1]][,2:3]<-us

s<-stack(s,r3)
r3





On Wed, May 7, 2014 at 2:50 PM, nevil amos <nevil.amos@gmail.com> wrote:

> I have now scripted a simple example to show what I am trying to do.  I
> wish to combine two input rasters (r1,r2) to give an output raster that has
> an attribute tables which contains IDs for the unique levels of
> combinations of r1 and r2:  this is the equivalent of a spatial analyst
> combine function in ArcGIS.
>
> r1 <- ratify(raster(matrix(c(5,5,6),3,3)),count=T)
> r2<-ratify(raster(t(matrix(c(7,7,8),3,3))),count=T)
>
> #i have manually constructed r3 the output that I wish to obtain.
> r3<-ratify(raster(matrix(c(1,1,2,1,1,2,3,3,4),3,3)),count=T)
> rStack<-stack(r1,r2,r3)
> names(rStack)<-c("r1","r2","r3")
> plot(rStack)
> #The step I cannot work out is the function that calculates the levels (
> and associated attributes) -  for unique spatail combinations of the values
> of r1 and r2
> #The actual rasters have millions of cells with hudreds ouf thousands of
> levels.
> r3@data@attributes[[1]]$r1<-c(5,6,5,6)
> r3@data@attributes[[1]]$r2<-c(7,7,8,8)
> print(r3)
>
> I then wish to join attribute tables ( each containing many attributes) of
> r1 and r2 to the value attributes (r1,r2) of raster r3.
>
>
> On Sat, Apr 12, 2014 at 12:52 AM, Jonathan Greenberg <jgrn@illinois.edu>wrote:
>
>> Nevil:
>>
>> Can you be more specific with what those attributes are?  You can use
>> a RAT table with rasters (?ratify in the raster package), but without
>> more specific details it is hard to give you a good answer.  What is
>> the data, and what, exactly, are you trying to accomplish?
>>
>> --j
>>
>> On Thu, Apr 10, 2014 at 11:14 PM, nevil amos <nevil.amos@gmail.com>
>> wrote:
>> > How can I combine tow overlapping Rasters in R maintaining such that the
>> > output raster cells are assigned the attributes of both the input
>> rasters.
>> >  - The equivalent of ARCGIS spatial analyst combine rasters followed by
>> > joining back to each of the input raster  attribute tables?
>> >
>> >         [[alternative HTML version deleted]]
>> >
>> > _______________________________________________
>> > R-sig-Geo mailing list
>> > R-sig-Geo@r-project.org
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
>>
>> --
>> Jonathan A. Greenberg, PhD
>> Assistant Professor
>> Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
>> Department of Geography and Geographic Information Science
>> University of Illinois at Urbana-Champaign
>> 259 Computing Applications Building, MC-150
>> 605 East Springfield Avenue
>> Champaign, IL  61820-6371
>> Phone: 217-300-1924
>> http://www.geog.illinois.edu/~jgrn/
>> AIM: jgrn307, MSN: jgrn307@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
>>
>
>

	[[alternative HTML version deleted]]

