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 1092605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:42:30+00:00 2026-05-16T23:42:30+00:00

The R documentation on arrays states The values in the data vector give the

  • 0

The R documentation on arrays states

The values in the data vector give the values in the array in the same order as they would occur in FORTRAN, that is “column major order,” with the first subscript moving fastest and the last subscript slowest.

It then later gives a clarifying example of this by loading data into a two dimensional array:

 > x <- array(1:20, dim=c(4,5))   # Generate a 4 by 5 array.
 > x
      [,1] [,2] [,3] [,4] [,5]
 [1,]    1    5    9   13   17
 [2,]    2    6   10   14   18
 [3,]    3    7   11   15   19
 [4,]    4    8   12   16   20

From experience with other languages, I would think x[1, 2], rather than x[2, 1], would be 2, but this is pretty easy to adjust my thinking to. However, just as quickly as I perform my mental model shift, the next example smashes it apart:

 > i <- array(c(1:3,3:1), dim=c(3,2))
 > i                             # i is a 3 by 2 index array.
      [,1] [,2]
 [1,]    1    3
 [2,]    2    2
 [3,]    3    1
 > x[i]                          # Extract those elements
 [1] 9 6 3

So, I can see what happened here is that we extracted elements x[1, 3], x[2,2], and x[3, 1]. Okay, but doesn’t this run completely counter to above claim of “column major order”?

From what I had understood, i should have been a 2 by 3 array, and R should have interpreted x[i] as x[i[1, 1], i[2, 1]], x[i[1, 2], i[2, 2]], .... However, what we observe is that, instead, R did x[i[1, 1], i[1, 2]], x[i[2, 1], i[2, 2]], ...

Is this a fundamental inconsistency in R, or have I completely misunderstood the documentation?

  • 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-16T23:42:31+00:00Added an answer on May 16, 2026 at 11:42 pm

    “column major order” only means that internally matrices are vectors ordered column by column; see that

    x[1:20]
    

    is 1, 2, 3, ..., 19, 20. Dimensions are ordered as usual in science — first rows, then columns, then depth, then hyperdepth…
    The third example is tricky: if i has the same number of columns that x has dimensions, it is interpreted as vectorized selection. If not, both i and x are flattered to by-column vectors and simple vector indexation rules apply… for instance x[t(i)] is 1:20[c(1,3,2,2,3,1)].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Official PHP documentation states that filter_var_array() supports array filtering in the following format: $data
The python documentation on array clearly states that the array conforms to the buffer
Documentation simply states that setting setAutosavingDelay to anything > 0 on the shared doc
The documentation on the Bigarray module is somewhat vague. It states that the purpose
If you read about cmpthese in the Perl Benchmark module's documentation, it states that
The official documentation states the following: . But I have noticed that there are
The Sun Documentation for DataInput.skipBytes states that it makes an attempt to skip over
I've noticed that for indexing Arrays, the MongoDB documentation suggests that Multikeys are what
Am I missing something in the Array documentation? I have an array which contains
I'm trying to iterate through an array of elements. jQuery's documentation says: jquery.Each() documentation

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.