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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:26:30+00:00 2026-06-05T21:26:30+00:00

I have two matrices. The first contains values, and the second contains names corresponding

  • 0

I have two matrices. The first contains values, and the second contains names corresponding to those values. I would like to sum the values in the first matrix by the corresponding name in the second matrix.

For instance, given the following two example matrices:

set.seed(9)
matrix_names=matrix(sample(paste("name",1:10,sep=""),replace=T),nrow=2,ncol=4); matrix_names
matrix_values=matrix(sample(1:10,8,replace=T),nrow=2,ncol=4); matrix_values

I would like to produce something like:

matrix_names   sum(matrix_values)
  name1                1
  name2                6 
  name3               15  
  name4               15
  name5                5

Any help is appreciated.

  • 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-05T21:26:31+00:00Added an answer on June 5, 2026 at 9:26 pm
    un <- unique(as.vector(matrix_names))
    df <- sapply(un, function(x) sum(matrix_values[which(matrix_names == x)]))
    df[order(names(df))]
    name1 name2 name3 name4 name5 
        1     6    15    15     5 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two 9x9 matrices, A and B. I would like to create a
I have two matrices (of approximately 300 x 100) and I would like to
I have two matrices like the following ones: '01/01/2010' 1 '02/01/2010' 2 '03/01/2010' 3
I have two matrices of different sizes. Let's just define matrix {a} as a(1:10)
In short: I have two matrices (or arrays): import numpy block_1 = numpy.matrix([[ 0,
I have two .csv files containing correlation matrices exported from R. One file contains
I have two very large matrices (60x25000) and I'd like to compute the correlation
I have two expressions in MATLAB that represent a 365x24 matrix. The first expression
I have two matrices ( x1 and x2 ) with same size. I would
I have two 4x4 OPENGL Matrices - 1st matrix holds rotation and position of

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.