Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中将基因表达数据转换为数字_R - Fatal编程技术网

在R中将基因表达数据转换为数字

在R中将基因表达数据转换为数字,r,R,我正在处理R中的前列腺基因表达数据(),并试图将所有条目转换为数值,以编写一个相似性函数。如何将因子中的所有条目转换为仅具有表达式值的数值?如果我索引到数据帧中 > prostate[5,4] [1] 3.17469778457247 2093 Levels: 0.133822364738809 ... normal 我只需要值3.17…文件的最后一行有字符数据。当R读入它时,它把一切都变成了因子,因为它不是数字。在bash中,您可以看到: tail -2 prostate_prepro

我正在处理R中的前列腺基因表达数据(),并试图将所有条目转换为数值,以编写一个相似性函数。如何将因子中的所有条目转换为仅具有表达式值的数值?如果我索引到数据帧中

> prostate[5,4]
[1] 3.17469778457247
2093 Levels: 0.133822364738809 ... normal

我只需要值3.17…

文件的最后一行有字符数据。当R读入它时,它把一切都变成了因子,因为它不是数字。在bash中,您可以看到:

tail -2 prostate_preprocessed.txt
AFFX-YEL021w/URA3_at 3.31255956783592 4.05800228545385 4.26348960812486 4.2180869800299 4.90599509636775 4.33488048792038 4.96535865133757 4.35350385526143 4.18529970123263 3.85103067777549 4.03836053811841 3.70345720098741 4.11379278781317 4.01121240340167 4.68296544299334 4.33584797205546 4.16864882878781 4.32781853396998 3.85145280458377 3.76586006943253 4.67388887037993 3.87182653639402 3.74997314075837 3.94258426954186 ...
tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor tumor
但您可以通过读取倒数第二行(再次bash)来修复它:

在R now中:

> prostate=read.table("prostate_preprocessed.txt", nrows=2135)
> prostate[4,5]
[1] 6.379761
编辑 ps这是一种奇怪的文件格式,因为您可能希望最后一行中的值作为列标题:

> cn=read.table("prostate_preprocessed.txt", skip=2135, colClasses="character")
> colnames(prostate)<-cn[1,]
cn=read.table(“prostate\u preprocessed.txt”,skip=2135,colClasses=“character”)
>colnames(prostate)本身并不是重复的,因为愚蠢的文件格式仍然会给他留下最后一行他可能不知道的示例名称,并且会弄乱他尝试的每个简单转换。
> cn=read.table("prostate_preprocessed.txt", skip=2135, colClasses="character")
> colnames(prostate)<-cn[1,]