删除空白值,而不是R中的整个列/行

时间:2020-05-19 15:55:41

标签: r heatmap missing-data

我使用以下代码读取了表格:

<div class="container">
  <div class="content">
    sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdasd
    sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdasd
    sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdasd
    sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasda
    sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdasd
    sdfdsfsdfsdfdsfsdsdfdsfs
    sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdasd
    sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdas
    sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdasd
    sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdasd
    sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdas
    sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdas
    sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdas
    sdfdsfsdfsdfdsfsdsdfdsfsdfsdfasdfsdfasdasdasdas
  </div>
</div>

某些列的条目较少。当我尝试计算重叠和相交时,会出现问题,我将空白值作为公用值。那么如何在不删除整个列或行的情况下排除这些空白值呢?

我正在使用Data<- read.table("1mo.txt", header = TRUE, sep = "\t", stringsAsFactors = F) 制作维恩图

RVenn

以下是数据:

Dat<-c(Data) 
Test = Venn(Dat) 
overlap(Test)
overlap(Test, c(1,2,3,4,6,7)) 
setmap(Test) 

1 个答案:

答案 0 :(得分:2)

很难从上面的例子中看出来,尝试这样的事情,我写一些类似于您的数据的事情:

x = structure(list(W = c("rno-miR-340-3p", "rno-miR-340-3p", "rno-miR-133a-3p"
), Ni = c("rno-miR-133a-3p", "rno-miR-133a-3p", "rno-miR-500-3p"
), Co = c("rno-miR-500-3p", "rno-miR-500-3p", "rno-miR-196b-5p"
), Fe = c("rno-miR-196b-5p", "rno-miR-196b-5p", ""), Cu = c("rno-miR-133a-3p", 
"rno-miR-133a-3p", ""), Al = c("rno-let-7c-2-3p", "", "")), class = "data.frame", row.names = c(NA, 
-3L))
write.table(x,"test.txt",quote=FALSE,sep="\t",row.names=FALSE)

我阅读了其中的内容,类似于您拥有的内容

Data = read.table("test.txt",sep="\t",header=TRUE)
Data
                W              Ni              Co              Fe
1  rno-miR-340-3p rno-miR-133a-3p  rno-miR-500-3p rno-miR-196b-5p
2  rno-miR-340-3p rno-miR-133a-3p  rno-miR-500-3p rno-miR-196b-5p
3 rno-miR-133a-3p  rno-miR-500-3p rno-miR-196b-5p                
               Cu              Al
1 rno-miR-133a-3p rno-let-7c-2-3p
2 rno-miR-133a-3p                
3                 

一种方法是将空白填充为NA:

Data = read.table("test.txt",sep="\t",header=TRUE,fill=TRUE,na.strings="",stringsAsFactors=FALSE)
Data
                W              Ni              Co              Fe
1  rno-miR-340-3p rno-miR-133a-3p  rno-miR-500-3p rno-miR-196b-5p
2  rno-miR-340-3p rno-miR-133a-3p  rno-miR-500-3p rno-miR-196b-5p
3 rno-miR-133a-3p  rno-miR-500-3p rno-miR-196b-5p            <NA>
               Cu              Al
1 rno-miR-133a-3p rno-let-7c-2-3p
2 rno-miR-133a-3p            <NA>
3            <NA>            <NA>

然后,如果要绘制超级维恩图,则要遍历各列,并省略NA:

library(RVenn)
ggvenn(Venn(sapply(Data,na.omit)[1:3]))

enter image description here