在特定列中保留带有值的行?

时间:2018-08-07 14:57:01

标签: r merge split bioconductor

我有一个下面的表,其中包含多个数据的合并表,我希望只在“ -log10.qvalue”列中保留表示值的行。

输入:

chr_enhancer Start_enhancer End_enhancer                     source_enhancer.x                      source_marks.x -log10.qvalue.x                     source_enhancer.y -log10.qvalue.y                       source_enhancer -log10.qvalue
       chr1      100036100    100036650 Reilly_Hu_12Opcw_H3K4me2_rep1_2_merge                                .               .   Reilly_Hu_12Opcw_H3K4me2_rep1_2_merge               . Reilly_Hu_12Opcw_H3K4me2_rep1_2_merge             .
       chr1      100042226    100043575 Reilly_Hu_12Fpcw_H3K4me2_rep1_2_merge Fetalbrain.H3K4me1_narrow_peak_2501         2.145 Reilly_Hu_12Fpcw_H3K4me2_rep1_2_merge              .    Reilly_Hu_12Fpcw_H3K4me2_rep1_2_merge             1.254
       chr1      100042310    100043300            enhancer_atlas_Fetal_brain Fetalbrain.H3K4me1_narrow_peak_2501         5.145        enhancer_atlas_Fetal_brain               1.356            enhancer_atlas_Fetal_brain             6.325 

输出:

 chr1      100042310    100043300            enhancer_atlas_Fetal_brain Fetalbrain.H3K4me1_narrow_peak_2501         5.145        enhancer_atlas_Fetal_brain               1.356            enhancer_atlas_Fetal_brain             6.325 

1 个答案:

答案 0 :(得分:1)

首先使用'grepl'获取所有以log10.开头的列,然后使用.检查并累加每行中的naapply
最后,返回行sum(x=='.'| is.na(x))==0

df[apply(df[,grepl('log10.',names(df))],1,function(x)sum(x=='.'| is.na(x))==0),]


chr_enhancer Start_enhancer End_enhancer   source_enhancer.x     source_marks.x X.log10.qvalue.x
3         chr1      100042310    100043300 enhancer_atlas_Fetal_brain Fetalbrain.H3K4me1_narrow_peak_2501            5.145  
source_enhancer.y X.log10.qvalue.y            source_enhancer X.log10.qvalue
3 enhancer_atlas_Fetal_brain            1.356 enhancer_atlas_Fetal_brain          6.325

数据

 df <- read.table(text="chr_enhancer Start_enhancer End_enhancer                     source_enhancer.x                      source_marks.x -log10.qvalue.x                     source_enhancer.y -log10.qvalue.y                       source_enhancer -log10.qvalue
       chr1      100036100    100036650 Reilly_Hu_12Opcw_H3K4me2_rep1_2_merge                                .               .   Reilly_Hu_12Opcw_H3K4me2_rep1_2_merge               . Reilly_Hu_12Opcw_H3K4me2_rep1_2_merge             .
       chr1      100042226    100043575 Reilly_Hu_12Fpcw_H3K4me2_rep1_2_merge Fetalbrain.H3K4me1_narrow_peak_2501         2.145 Reilly_Hu_12Fpcw_H3K4me2_rep1_2_merge              .    Reilly_Hu_12Fpcw_H3K4me2_rep1_2_merge             1.254
       chr1      100042310    100043300            enhancer_atlas_Fetal_brain Fetalbrain.H3K4me1_narrow_peak_2501         5.145        enhancer_atlas_Fetal_brain               1.356            enhancer_atlas_Fetal_brain             6.325 
                 ",header=T)