Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4333680
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:25:35+00:00 2026-05-21T10:25:35+00:00

I have a question on how to apply R functions to multidimensional arrays. For

  • 0

I have a question on how to apply R functions to multidimensional arrays.

For example, consider this operation, where I reduce an entry by the sum of other entries.

ppl["2012",,,,,1] <- ppl["2012",,,,,1]
- ppl["2012",,,,,2] - ppl["2012",,,,,3] - ppl["2012",,,,,4]
- ppl["2012",,,,,5] - ppl["2012",,,,,6] - ppl["2012",,,,,7]
- ppl["2012",,,,,8]

While in this case subtracting individual values might be feasible, I would prefer a vector-oriented approach.

If I was familiar with multidimensional matrix algebra I could probably come up with the matrix that performs the necessary operation when applied, but this is too complex given the number of dimensions involved.

sum(ppl["2012",,,,,2:8]) is not the correct solution, as sum() always returns scalars.

I could use loops that perform the necessary operations, but that contradicts the paradigm of vector-oriented programming.

Thanks for your help!

Edit: And here is the solution to the original problem, based on Andrie’s suggestion:
ppl[paste(i),land,,,,1] <- ppl[paste(i),land,,,,1] - apply(ppl[paste(i),land,,,,2:8],c(1,2,3),sum)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:25:36+00:00Added an answer on May 21, 2026 at 10:25 am

    EDITED

    Here is an example of using apply and sum to return the sum computed across a multi-dimensional table:

    mat <- array(1:27, dim=c(3, 3, 3))
    

    Let’s say you’d like to compute the sum of the third dimension for each combination of the first two dimension.

    Then the code to do this becomes:

    apply(mat, c(1,2), sum)
    
         [,1] [,2] [,3]
    [1,]   30   39   48
    [2,]   33   42   51
    [3,]   36   45   54
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question deals with CoffeeScript but the same issues still apply to JavaScript. Consider
I have the following functions. WordPress functions, but this is really a PHP question.
I have question. I have some app on facebook and getting this error Fatal
thanks to wonderful responses to this question I understand how to call javascript functions
I have downloaded sample code from Apple Center.I also have gone through following question:
If I have a form of about 40 questions, how do I apply the
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass
I have question about XSLT1.0. The task is to write out in HTML all
I have Question and QuestionTypes. In Question table there is a foreign key that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.