Given a 100×100 matrix, we want to compute a 20×20 matrix, every cell of it represents the mean of a 5×5 square of the original matrix.
How to perform it? (If you have any better name for this operation please comment to rename question).
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here are a couple of options.
The straightforward approach is to use
aggregate()from the raster package:For a more elegant or obfuscated approach (depending on your point of view) use a couple of matrix multiplications: