Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.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_Dataframe_Subset - Fatal编程技术网

R:基于多行中的列条目的子集数据帧

R:基于多行中的列条目的子集数据帧,r,dataframe,subset,R,Dataframe,Subset,我有一个数据框,其中包含几个基因的信息,格式类似于: chr start end Gene Region 1 100 110 Bat Exon 1 120 130 Bat Intron 1 500 550 Ball Upstream, Downstream 1 590 600 Ball Intron, Upstream 1 900 980 Mit

我有一个数据框,其中包含几个基因的信息,格式类似于:

chr    start    end    Gene    Region
1    100    110    Bat     Exon
1    120    130    Bat     Intron
1    500    550    Ball    Upstream, Downstream
1    590    600    Ball    Intron, Upstream
1    900    980    Mit     Promoter, Upstream
我想对数据进行子集划分,以删除区域列中包含“外显子”或“启动子”基因的任何行。我一直在使用:

Regions <- subset(Table, Region == "Intron" | Region== "DownStream" | Region =="Upstream" | Region=="DownStream,Upstream")
我想要的是:

chr    start    end    Gene    Region
1    500    550    Ball    Upstream, Downstream
1    590    600    Ball    Intron, Upstream

尝试使用
grepl

df[!grepl("Exon|Promoter", df$Region),]
#  chr start end Gene               Region
#2   1   120 130  Bat               Intron
#3   1   500 550 Ball Upstream, Downstream
#4   1   590 600 Ball     Intron, Upstream
我不清楚为什么要删除带有“Intron”的第2行。请解释一下

编辑: 我想我现在明白了,试试这个:

temp <- df$Gene[grepl("Exon|Promoter", df$Region)]
df[!df$Gene %in% temp,]
#  chr start end Gene               Region
#3   1   500 550 Ball Upstream, Downstream
#4   1   590 600 Ball     Intron, Upstream

temp为什么要删除第2行(区域列中有“内含子”)?每行表示基因中的一个更改位置。我不想看到由启动子或外显子引起的变化,我想删除所有在这些区域有任何变化的基因。看看我的更新答案——这就是你一直在寻找的吗?
temp <- df$Gene[grepl("Exon|Promoter", df$Region)]
df[!df$Gene %in% temp,]
#  chr start end Gene               Region
#3   1   500 550 Ball Upstream, Downstream
#4   1   590 600 Ball     Intron, Upstream