如何将矩阵转换为中的R 1维阵列 [英] How to convert a matrix to a 1 dimensional array in R

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

问题描述

您好我有一个矩阵文件就是32X48,我希望把所有的值入河右一维数组现在我只能得到数据的最后一行。

Hi I have a matrix file that is 32X48 and I want to put all of the values into a single dimensional array in R. Right now I am only able to get the last row of data.

trgtFN_intensity <- "1074_B09_1- 4_5mM_Xgal_7d_W.cropped.resized.grey.png.red.median.colony.txt";

read.table(trgtFN_intensity, sep="\t") -> tmp_int

maxrow_int <- nrow(tmp_int);
maxcol_int <- ncol(tmp_int);

Elts_int <- -10;
for (row in 1:maxrow_int){rbind(Elts_int, tmp_int[row,]) -> Elts_int;}
av_int <- mean(Elts_int[Elts_int!=-10]);
sd_int <- sd(Elts_int[Elts_int!=-10]);

penalty_Matrix <- matrix(0, nrow=1536, ncol=1);
for (row in 1:maxrow_int)
{
    for (col in 1:maxcol_int)
{ 
    penalty_Matrix[col] <- tmp_int[row, col];

}
}

outFN <- paste(trgtFN_intensity, "array", sep=".");
write.table(penalty_Matrix, file = outFN, col.names=F, row.names=F, sep ="\t")

任何帮助将大大AP preciated。谢谢

Any help would be greatly appreciated. Thank you

推荐答案

如果我们谈论data.frame,那么你应该问问自己,是同一类型的变量?如果是这样的话,你可以rapply,或不公开使用,因为data.frames的名单,在他们的灵魂深处......

If we're talking about data.frame, then you should ask yourself are the variables of the same type? If that's the case, you can use rapply, or unlist, since data.frames are lists, deep down in their souls...

 data(mtcars)
 unlist(mtcars)
 rapply(mtcars, c) # completely stupid and pointless, and slower

这篇关于如何将矩阵转换为中的R 1维阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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