0

I have a matrix of 256*256 ,I need to break this matrix to get 1024 blocks (256*256/(8*8)). Then I need calculate mean,standard deviation,Kurtosis,standard deviation of each block (1024 blocks)

The dataset which I want from from matrix is

S.no Mean standard deviation Kurtosis Skewness 1 2 . . . . 1024

I am stuck in looping and retrieving the values to compute the statistics.

Praveen Chougale
  • 355
  • 3
  • 11
  • 1
    Sounds like a challenge. Where are you stuck exactly? Can you show us your code? Also please read - [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to make a great R reproducible example?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Shique May 29 '18 at 07:53
  • 1
    Possible duplicate: [Function to split a matrix into sub-matrices in R](https://stackoverflow.com/questions/24299171/function-to-split-a-matrix-into-sub-matrices-in-r/24299527#24299527) – markus May 29 '18 at 07:59
  • Yes sure... I have converted an Image to a matrix of 256*256.First I am trying to calculate mean,I am getting error,Below is the code. y – Praveen Chougale May 29 '18 at 08:00
  • @PraveenChougale Try `apply(X = asa, MARGIN = 3, FUN = mean)`. It should return a vector of length 1024. – markus May 29 '18 at 08:22
  • Yes thanks a lot got it.But I need summary of each block,by using FUN=mean ,I am getting only mean – Praveen Chougale May 29 '18 at 08:36
  • 1
    @PraveenChougale Please put the additional information from your comments in your question, i.e. **edit your question:** https://stackoverflow.com/posts/50579071/edit – jogo May 29 '18 at 10:04

1 Answers1

1

m is your matrix. yourMatrixFunction is a function you need to define that works on a single 8x8-matrix and acquires what you want.

m <- matrix(1,nrow=256,ncol=256)

first <- seq(1,256,by=8)
last  <- rep(8,length(first)) %>% cumsum

pair  <- Map(function(...)cbind(...),first,last) %>% expand.grid(.,.)
first <- pair[[1]]
last  <- pair[[2]]

all_m <- Map(function(x,y) m[x[1]:x[2],y[1]:y[2]],x=first,y=last)

lapply(all_m,yourMatrixFunction)
Andre Elrico
  • 9,945
  • 4
  • 45
  • 65