0
如何從具有n個以上基因的數據集中刪除行。如何過濾列數超過n的條目的數據幀
data1 <- Re_leve logp chr start end CNA Genes
1 1.5 1 739400 756200 gain Trp1,Eggier
1 8.3 1 127730 128210 gain Zranb3,R3hdm1,.....
如何從具有n個以上基因的數據集中刪除行。如何過濾列數超過n的條目的數據幀
data1 <- Re_leve logp chr start end CNA Genes
1 1.5 1 739400 756200 gain Trp1,Eggier
1 8.3 1 127730 128210 gain Zranb3,R3hdm1,.....
您可以嘗試
library(stringr)
n <- 1
df1[!str_count(df1$Genes, ',')+1 >n,]
試試這個:
#dummy data
data1 <- data.frame(x=1:3,
Gene=c("asdf,asdf,ee,d","asdf","dfd,sdf"),
stringsAsFactors = FALSE)
#minimum number of genes
n <- 1
#subset
data1[sapply(data1$Gene,function(i)length(unlist(strsplit(i,",")))) > n, ]
# x Gene
# 1 1 asdf,asdf,ee,d
# 3 3 dfd,sdf
@beginner你能成爲一個更具體一點? – akrun 2015-02-11 13:08:01
@beginner你不是再次問同樣的問題嗎? http://stackoverflow.com/questions/28109327/subset-only-those-rows-whose-intervals-does-not-fall-within-another-data-frame – zx8754 2015-02-11 13:10:27
@beginner你是否嘗試過鏈接中的解決方案。此外,這個問題和描述與您的後續問題完全不同。 – akrun 2015-02-11 13:13:13