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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:57:01+00:00 2026-05-26T07:57:01+00:00

I am running double forloop for two matrices. but one matrix has around 90,000

  • 0

I am running double forloop for two matrices. but one matrix has around 90,000 rows.
it is too slow in R. so, I would like to take apply function for this if possible.

  1. One matrix has 90,000 X 1 column with string information per row. e.g 1row value(ID) AAAA12
  2. The other matrix has also around 90,000 but a bit more than 90,000 X 2 columns, so for one row(ID) has AAAA23 in 1st column and corresponding month information e.g AAAA23 Jan
    And 2nd row, AAAA12 Feb …etc

So, I would like to merge one column of matched month information from 2nd matrix to 1st mat.

1st row of output mat is going to be AAAA12 Feb. instead of using for loop, how can I generate such a matrix quickly?

Any input will be helpful.

  • 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-26T07:57:02+00:00Added an answer on May 26, 2026 at 7:57 am

    The following might do the trick:

    m1 <- matrix(c('AAAA12', 'AAAA23', 'AAAA14'))
    m2 <- cbind(c('AAAA23', 'AAAA12', 'AAAA14'), c('Jan', 'Feb', 'Mar'))
    
    cbind(m1, m2[match(m1[,1], m2[,1]),2])
    

    Which gives you

         [,1]     [,2] 
    [1,] "AAAA12" "Feb"
    [2,] "AAAA23" "Jan"
    [3,] "AAAA14" "Mar"
    

    …And then timing it on around 90000 rows shows it takes around 0.04 seconds:

    x <- outer(outer(outer(LETTERS, LETTERS, paste, sep=''), 
                     LETTERS, paste, sep=''), 1:5, paste, sep='')
    set.seed(42)
    m1 <- matrix(sample(x, 85000))
    m2 <- cbind(x, seq_along(x))
    
    system.time( cbind(m1, m2[match(m1[,1], m2[,1]),2]) ) # 0.04 seconds
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One is supposed to use double buffering when running locally, but to not use
I found that running Math.Log10(double.Epsilon) will return about -324 on machine A, but will
Running the following C# code through NUnit yields Test.ControllerTest.TestSanity: Expected: `<System.DivideByZeroException>` But was: null
I have a site that has been running fine for awhile. Ran an SVN
Running a quick experiment related to Is double Multiplication Broken in .NET? and reading
I'm running into a double free, and I can't see where it's happening. The
I keep on running across code that uses double-checked locking, and I'm still confused
When using double or float data type in an iPhone app, I am running
After running the following lines : double d=Float.parseFloat(9.99); System.out.println(+d); I got this : 9.989999771118164
My code is running elevated but nothing can see/execute c:\windows\system32\rstrui.exe (System Restore Point UI).

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.