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

Methods so far:

- Sierpinski Triangle in plotmath
- Another sierpinski triangle in plotmath
- Sierpinski triangle using characters
**Today: Using R matrices to create a sierpinski carpet**

```
#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)
```

## Share this post

Twitter

Google+

Facebook

Reddit

LinkedIn

StumbleUpon

Pinterest

Email