简体   繁体   中英

Combine 2 2d matrices in one 2d matrix R

I have 2 two-dimensional matrices which I try to combine into 1. There are 3 common sets in each matrix, voyages barges and category's. I have an binary matrix which assigns barges to voyages, and I have a matrix which states the capacity of different categorys of cargo per barge. Now what I try to create is a table which gives the capacity per voyage based on which barge is assigned to it. I made some example data, my real data is tables and data frames in R;

在此处输入图像描述

table 1: capacity of category c for barge b

在此处输入图像描述

table 2: = 1 if barge b goes on voyage v

Now based on these 2 tables I want to get a table, which gives me the cap of each voyage, as follows;

在此处输入图像描述

table 3: output table

table 1 and 2 are both of type matrix in R

After I work the data I import it in python, so if someone knows how to do it there instead of in R, that would work fine as well.

Regards

You can try tcrossprod

tcrossprod(tbl1,tbl2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM