执行此代码时,获得了以下错误: 我想将结果转换为for循环中的数据帧。问题出在对象" y.1"中,结果数据帧的值为3/4/5。我想要一个包含5列的数据帧,并用其他值替换为零,将其保留为零。
model_reactants是来自sbml.model的反应物列表,它是类"模型"的rsbml对象。
model_reactants=sapply(reactions(sbml.model), function(x) x@reactants)
x.1<- data.frame(matrix(0,ncol = 1, nrow = 4155))
y.1<- data.frame(matrix(0,ncol = 5, nrow = 4155))
for (r in 1:length(model_reactants)){
x=names(model_reactants[r])
y=names(model_reactants[[r]])
x.1[r,]=c(x)
y.1[r,]=c(y)
}
Error in `[<-.data.frame`(`*tmp*`, r, , value = c("M_13dampp_c", "M_h2o_c", :
replacement has 3 items, need 5
我们在模型中有4155个反应作为条目。我们希望将反应物作为单独的列放入数据框中。一些反应具有2,3,4,5至6种反应物,并且它们在不同的反应条目中不同。但是我们当前使用的代码重复了只有2个反应物的条目中第一和第二列的值。
eg: model: reaction1:
a+b-> c+d
reaction2:
e+f+g->h+i+j
expected output:
col 1 col 2 col 3
row 1 a b NA
row 2 e f g
这里给出了model_reactants的样本结构。
dput(model_reactants [1:5]) 结构(列表(R_13DAMPPOX =结构(列表(M_13dampp_c =, M_h2o_c =, M_o2_c =),. Name = c(&#34; M_13dampp_c&#34;, &#34; M_h2o_c&#34;,&#34; M_o2_c&#34;)),R_24_25VITD2Hm =结构(列表(M_h_m =, M_nadph_m =, M_o2_m =, M_25hvitd2_m =),. Name = c(&#34; M_h_m&#34;, &#34; M_nadph_m&#34;,&#34; M_o2_m&#34;,&#34; M_25hvitd2_m&#34;)),R_24_25VITD3Hm =结构(列表( M_h_m =, M_nadph_m =, M_o2_m =, M_25hvitd3_m =),. Name = c(&#34; M_h_m&#34;, &#34; M_nadph_m&#34;,&#34; M_o2_m&#34;,&#34; M_25hvitd3_m&#34;)),R_25VITD2Hm =结构(列表( M_h_m =, M_nadph_m =, M_o2_m =, M_25hvitd2_m =),. Name = c(&#34; M_h_m&#34;, &#34; M_nadph_m&#34;,&#34; M_o2_m&#34;,&#34; M_25hvitd2_m&#34;)),R_25VITD3Hm =结构(列表( M_h_m =, M_nadph_m =, M_o2_m =, M_25hvitd3_m =),. Name = c(&#34; M_h_m&#34;, &#34; M_nadph_m&#34;,&#34; M_o2_m&#34;,&#34; M_25hvitd3_m&#34;))),。Name = c(&#34; R_13DAMPPOX&#34;, &#34; R_24_25VITD2Hm&#34;,&#34; R_24_25VITD3Hm&#34;,&#34; R_25VITD2Hm&#34;,&#34; R_25VITD3Hm&#34; ))