2016-12-14 7 views
0

Rの下では、色の組み合わせを生成しようとしていましたが、このあとで使用前の組み合わせをインポートし、すべての組み合わせに対してこれを削除し、組み合わせ。私はこれらの事前に使用されたものを取り除くのに苦労しました。ご協力いただきありがとうございます! はすべて、最高の - カルロス組み合わせのリストを作成して使用済みのものを削除する

rm(list=ls());ls() 
library("gtools") 

# Generate all colors combinations 
colors<-c("RED","GREEN","BLUE","BLACK","PINK") 
size.of.combinations<-4 
all.possible.combinations<-permutations(length(colors),size.of.combinations,colors,repeats.allowed=T) 

# Import used data 
used.comb<- read.table(file = "used.txt", header = TRUE); 
used.comb<-as.matrix(used.comb) 

# Removed pre-used combinations 
comb.available<-all.possible.combinations-used.comb #here is the problem 

my.data<-data.frame(comb.available) 
write.table(my.data, file = "data.csv", sep = ",", col.names = NA, qmethod = "double") 

答えて

1

このによる前に使用の組み合わせを削除し、それが正常に動作する必要があります(他の線は大丈夫です)。

# Removed pre-used combinations 
comb.available<- 
      do.call(rbind, strsplit(setdiff(
       apply(all.possible.combinations, 1, function(x) paste(x, collapse=',')), 
       apply(used.comb, 1, function(x) paste(x, collapse=','))), split=',')) #this should work fine 
+0

ありがとうございました!それは完全に動作します! –

関連する問題