如何将非矩形矩阵读入R [英] How to read a non-rectangular matrix into R

查看:130
本文介绍了如何将非矩形矩阵读入R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的基因ID矩阵,后面跟着一系列的引导值.

I have a large matrix of gene ID's followed by a series of bootstrap values.

例如:

NM_001040105 1.80711736583 0.877742720548 1.0842704195 1.80711736583 0.505992862434 0.877742720548 1.37340919803 0.722846946334 1.0842704195 1.0842704195 2.52996431217 1.80711736583 1.0842704195 2.52996431217 1.80711736583 1.0842704195 1.37340919803 1.37340919803 1.0842704195 1.37340919803 0.877742720548 1.0842704195 2.52996431217 1.80711736583 1.80711736583 0.877742720548 0.877742720548 0.877742720548 1.80711736583 1.0842704195 0.722846946334 0.877742720548 0.722846946334 1.80711736583 0.877742720548 8.31273988284 1.37340919803 0.722846946334 1.0842704195 1.0842704195 1.0842704195 1.37340919803 2.52996431217 1.80711736583 1.37340919803 1.37340919803 8.31273988284 3.97565820484 1.80711736583 ...

NM_001040105 1.80711736583 0.877742720548 1.0842704195 1.80711736583 0.505992862434 0.877742720548 1.37340919803 0.722846946334 1.0842704195 1.0842704195 2.52996431217 1.80711736583 1.0842704195 2.52996431217 1.80711736583 1.0842704195 1.37340919803 1.37340919803 1.0842704195 1.37340919803 0.877742720548 1.0842704195 2.52996431217 1.80711736583 1.80711736583 0.877742720548 0.877742720548 0.877742720548 1.80711736583 1.0842704195 0.722846946334 0.877742720548 0.722846946334 1.80711736583 0.877742720548 8.31273988284 1.37340919803 0.722846946334 1.0842704195 1.0842704195 1.0842704195 1.37340919803 2.52996431217 1.80711736583 1.37340919803 1.37340919803 8.31273988284 3.97565820484 1.80711736583 ...

问题在于,并非每个基因都具有相同数量的引导程序值,因此矩阵不是矩形的,因此read.table()无法正常工作. readLines()也不一定能正常工作,因为我需要将基因ID与它们各自的引导程序值相关联.有什么办法可以将这样的表读到R中吗?

The problem is that not every gene has the same amount of bootstrap values, so the matrix is not rectangular, thus read.table() won't work. readLines() won't necessarily work either, as I need the gene IDs to be associated with their respective bootstrap values. Is there any way to read a table like this into R?

谢谢, 马库斯

推荐答案

一种合理的执行方式,假设testreadLines()的结果:

A reasonably performant way, assuming test is the result of readLines():

space <- regexpr(" ", test, fixed=TRUE)
id <- substring(test, 1L, space-1L)
setNames(strsplit(substring(test, space+1L), " ", fixed=TRUE), id)

这篇关于如何将非矩形矩阵读入R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆