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

  • Home
  • SEARCH
  • 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 9157261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:58:18+00:00 2026-06-17T12:58:18+00:00

I am looking to make a simple code in R to generate a matrix

  • 0

I am looking to make a simple code in R to generate a matrix like the one below..

I know you start one like:

 for(i in 1:10){

But I am not sure where to go from here. I know I can just use outer(1:10,1:10) but am looking to use a for() do() statement.

    1   2   3   4   5   6   7   8   9   10
 1  1   2   3   4   5   6   7   8   9   10  
 2  2   4   6   8   10  12  14  16  18  20  
 3  3   6   9   12  15  18  21  24  27  30  
 4  4   8   12  16  20  24  28  32  36  40  
 5  5   10  15  20  25  30  35  40  45  50  
 6  6   12  18  24  30  36  42  48  54  60  
 7  7   14  21  28  35  42  49  56  63  70  
 8  8   16  24  32  40  48  56  64  72  80  
 9  9   18  27  36  45  54  63  72  81  90 
 10 10  20  30  40  50  60  70  80  90 100  
  • 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-06-17T12:58:20+00:00Added an answer on June 17, 2026 at 12:58 pm

    for me to explain outer, you need 2 loops ( at least how I would do if I want to implement it)

    v <- c()
    for(i in 1:10)
      for(j in 1:10)
        v <- c(v,i*j)      ## This is SLOW! (naughty)
    matrix(v,ncol=10,nrow=10)
    

    EDIT

    In my last implementation I allocate dynamically the size of the matrix which is very slow. It is better to allocate the matrix before the loops, something like this:

    xx <- matrix(NA,ncol=10,nrow=10)
    for(i in 1:10)
      for(j in 1:10)
        xx[i,j] <- i*j 
    

    Another way to do with vectors:

    I <- 1:10
    J <- 1:10
    I %*% t(J)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for simplest blogger template that i can make with simple code.
I'm looking to make a simple volume manager app. I know it has been
Today I am looking into how to make a simple XML parser in Cocoa
I am looking for a simple way to make a piece of text, which
I'm looking to make a show action of one of my controllers the root.
I'm not really sure if what I am looking for has a name, so
I was looking for help last week to get a simple javascript code made
I am attempting to make a simple shell program, and looking at a few
How do you make a simple navigation in Code Igniter? I keep tripping up
Simple Substitution Cipher. I'm trying to make a looping construct that would loop through

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.