Fractals with matrices - sierpinski carpet

Today in my ongoing quest to generate fractals in Rstart using every available avenue: generating a sierpinski carpet with matrices.

Methods so far:

#rstats #fractal
library(raster)

f <- function(x) {
  z <- x
  z[] <- ' '
  rbind(
    cbind(x,x,x),
    cbind(x,z,x),
    cbind(x,x,x)
  )
}

m=matrix('#')
m=f(f(f(f(f(m)))))
g=matrix(m=='#', nrow=nrow(m))
plot(raster(g), ann=F, axes=F, box=F, legend=F)