简体   繁体   English

将 2 个 2d 矩阵合并为一个 2d 矩阵 R

[英]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.我有 2 个二维矩阵,我尝试将它们组合成 1 个。每个矩阵中有 3 个公共集,航程驳船和类别。 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;我做了一些示例数据,我的真实数据是R中的表格和数据框;

在此处输入图像描述

table 1: capacity of category c for barge b表 1:驳船 b 类别 c 的容量

在此处输入图像描述

table 2: = 1 if barge b goes on voyage v表 2:= 1 如果驳船 b 继续航行 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表3:output表

table 1 and 2 are both of type matrix in R表 1 和表 2 都是 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.在我处理完数据后,我将其导入 python,所以如果有人知道如何在那里而不是在 R 中进行操作,那也可以正常工作。

Regards问候

You can try tcrossprod你可以试试tcrossprod

tcrossprod(tbl1,tbl2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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