R 或 MATLAB - 匹配列名称以修改矩阵中的相应单元格
我想将下面矩阵中以 NODE 作为标题的列转换为其相应的基因,如下所示:
NODE Gene1 Gene2 Gene3 Gene4 Gene5 NODE1 NODE2 NODE3
1 NODE1 0.98 0.98 NA NA NA NA NA NA
2 NODE2 NA NA 0.8 0.8 NA NA NA NA
3 NODE3 NA NA NA NA 0.72 0.72 NA NA
4 NODE4 NA NA NA NA NA NA 0.6 0.6
因为
NODE1 = Gene1 and Gene2
NODE2 = Gene3 and Gene4
NODE3 = Gene5 and NODE1 = Gene5 and Gene 1 and Gene2
我想将 NODE1 NODE2 和 NODE3 列中的单元格移动到其相应的基因列以输出如下文件:
NODE Gene1 Gene2 Gene3 Gene4 Gene5
1 NODE1 0.98 0.98 NA NA NA
2 NODE2 NA NA 0.8 0.8 NA
3 NODE3 0.72 0.72 NA NA 0.72
4 NODE4 0.6 0.6 NA 0.6 0.6
是否有这样做的方法?我可以使用 R 或 MATLAB 来执行此操作吗?
最好的问候,
凯瑟琳
I would like to convert the column with NODE as header in a Matrix below to their corresponding Gene as follows:
NODE Gene1 Gene2 Gene3 Gene4 Gene5 NODE1 NODE2 NODE3
1 NODE1 0.98 0.98 NA NA NA NA NA NA
2 NODE2 NA NA 0.8 0.8 NA NA NA NA
3 NODE3 NA NA NA NA 0.72 0.72 NA NA
4 NODE4 NA NA NA NA NA NA 0.6 0.6
As
NODE1 = Gene1 and Gene2
NODE2 = Gene3 and Gene4
NODE3 = Gene5 and NODE1 = Gene5 and Gene 1 and Gene2
I would like to move cells in NODE1 NODE2 and NODE3 columns to their corresponding Gene colunms to output a file like this:
NODE Gene1 Gene2 Gene3 Gene4 Gene5
1 NODE1 0.98 0.98 NA NA NA
2 NODE2 NA NA 0.8 0.8 NA
3 NODE3 0.72 0.72 NA NA 0.72
4 NODE4 0.6 0.6 NA 0.6 0.6
Are there any methods of doing this? Can I use R or MATLAB to do this?
Best regards,
Catherine
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Matlab 中,您可以这样做:
一些注意事项:
您可能需要运行两次才能根据条目的配置来展开所有条目,但我认为您已经从代码中了解了如何执行此操作。< /p>
示例结果的 Node4 行存在轻微错误。
这是用两个嵌套的 for 循环编码的。对于大型矩阵来说缓慢且低效,但更容易理解。您可能必须对大型矩阵进行矢量化以缩短执行时间。
In Matlab you can do it like this:
Some caveats:
You maybe have to run this twice to expand all the entries depending on the configuration of entries, but I think you get the idea how to do this from the code.
there's a slight error in the Node4 line of your example result.
This is coded with two nested for loops. Slow and inefficient for large matrices, but easier to understand. You maybe have to vectorize for large matrices to improve execution time.