2015-02-11 154 views

回答

2

您可以嘗試

library(stringr) 
n <- 1 
df1[!str_count(df1$Genes, ',')+1 >n,] 
+0

@beginner你能成爲一個更具體一點? – akrun 2015-02-11 13:08:01

+1

@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

+0

@beginner你是否嘗試過鏈接中的解決方案。此外,這個問題和描述與您的後續問題完全不同。 – akrun 2015-02-11 13:13:13

2

試試這個:

#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