【发布时间】:2019-03-08 07:06:36
【问题描述】:
我正在处理 R 中的一些基因组文件。我有一个大矩阵,其格式如下例所示,其中列是样本,行是基因(实际矩阵有 205 列和超过 22k 行。
GSM1304852 GSM1304853 GSM1304854 GSM1304855
1007_s_at 2.3945368 2.27518369 2.1611630 1.9641833
1053_at 0.1051084 0.06160802 0.3421762 0.3593916
117_at -0.4597124 -0.52310349 -0.4436059 -0.6370277
121_at 0.9333566 1.13180904 0.9975700 1.0079778
我还有一个格式如下例的数据框,其中geo_accession 与矩阵第一行中的 id 相同。
title geo_accession Age Disease_State Gender pH PMI Race RIN tissue
GSM1304852 bipolar_hip_10 GSM1304852 52 bipolar disorder M 6.7 23.5 W 6.3 hippocampus
GSM1304853 bipolar_hip_11 GSM1304853 50 bipolar disorder F 6.4 11.7 W 6.8 hippocampus
GSM1304854 bipolar_hip_12 GSM1304854 28 bipolar disorder F 6.3 22.3 W 7.7 hippocampus
GSM1304855 bipolar_hip_13 GSM1304855 55 bipolar disorder F 6.4 17.5 W 7.6 hippocampus
GSM1304856 bipolar_hip_14 GSM1304856 58 bipolar disorder M 6.8 27.7 W 7.0 hippocampus
GSM1304857 bipolar_hip_15 GSM1304857 28 bipolar disorder M 6.2 27.4 W 7.7 hippocampus
我需要对与某个组织相关联的矩阵中的所有列进行子集化(在完整的数据框中有 3 种组织),因此最后我需要有 3 个矩阵。
例如:从矩阵中我只想取与hippocampus相关的列:
matrix # an R matrix object
DataFrame # an R dataframe
DFhip <- DataFrame[ which(tissue == 'hippocampus',]
GSMlist <- DFhip$geo_accesion
MatrixHip <- matrix[GSMlist,] # I know this is the wrong syntax, it's just to let you understand
我对 R 比较陌生,不习惯子集矩阵。
【问题讨论】:
标签: r