2

这似乎是一个简单的问题,但让我很头疼(这不是功课,而是实际研究中的症结所在)

我有一个包含 2266 个级别的列表。该列表看起来有点像这样:

[1] ~/folder1/folder1/a.bin
[2] ~/folder1/folder1/b.bin
[3] ~/folder1/folder1/c.bin
[4] ~/folder1/folder2/a.bin
[5] ~/folder1/folder2/b.bin
[6] ~/folder1/folder2/c.bin

解释一下:列表是我正在使用该readBin函数读取的二进制文件的文件名。我想将每一行与其他每一行进行比较,所以我想要的是两列,其中包含所有独特的组合,从我的单列派生

(choose 2266,2)告诉我,我们的单列有 2566245 个组合成两个。

` expand.grid()似乎让我走到了一半。但是我需要的组合是我需要的四倍:我得到两行,每行 5132490。这意味着存在重复:1 + 2 和 2 + 1 对我的目的来说是相同的。

expand.grid.dfwithunique=TRUE似乎也没有帮助。

我的最后一个想法是 md5 对 500 万行中的每一行进行哈希处理,并尝试以这种方式检测重复项。

我正在寻找制作两个列表的方法,这些列表涵盖了我列表的 2566245 个组合。或者以某种方式删除所有重复项。我想我并不完全热衷于使用 R 并且已经研究了 awk 或 sed 来做同样的事情。虽然还没有成功。

4

1 回答 1

2

我认为您正在寻找combn看起来像expand.grid,使用@Arun 数据,

v <- c("~/folder1/folder1/a.bin", 
       "~/folder1/folder1/b.bin", 
       "~/folder1/folder1/c.bin", 
       "~/folder1/folder2/a.bin", 
       "~/folder1/folder2/b.bin", 
       "~/folder1/folder2/c.bin")
do.call(rbind,combn(v,2,simplify=F))

    [,1]                      [,2]                     
 [1,] "~/folder1/folder1/a.bin" "~/folder1/folder1/b.bin"
 [2,] "~/folder1/folder1/a.bin" "~/folder1/folder1/c.bin"
 [3,] "~/folder1/folder1/a.bin" "~/folder1/folder2/a.bin"
 [4,] "~/folder1/folder1/a.bin" "~/folder1/folder2/b.bin"
 [5,] "~/folder1/folder1/a.bin" "~/folder1/folder2/c.bin"
 [6,] "~/folder1/folder1/b.bin" "~/folder1/folder1/c.bin"
 [7,] "~/folder1/folder1/b.bin" "~/folder1/folder2/a.bin"
 [8,] "~/folder1/folder1/b.bin" "~/folder1/folder2/b.bin"
 [9,] "~/folder1/folder1/b.bin" "~/folder1/folder2/c.bin"
[10,] "~/folder1/folder1/c.bin" "~/folder1/folder2/a.bin"
[11,] "~/folder1/folder1/c.bin" "~/folder1/folder2/b.bin"
[12,] "~/folder1/folder1/c.bin" "~/folder1/folder2/c.bin"
[13,] "~/folder1/folder2/a.bin" "~/folder1/folder2/b.bin"
[14,] "~/folder1/folder2/a.bin" "~/folder1/folder2/c.bin"
[15,] "~/folder1/folder2/b.bin" "~/folder1/folder2/c.bin"

编辑

我认为路径格式过度使问题复杂化。如果我们使用例如字母代替文件名,我们会得到:

do.call(rbind,combn(letters[1:4],2,simplify=F))
     [,1] [,2]
[1,] "a"  "b" 
[2,] "a"  "c" 
[3,] "a"  "d" 
[4,] "b"  "c" 
[5,] "b"  "d" 
[6,] "c"  "d"  

因此,如您所见,没有重复。

于 2013-03-09T10:23:07.513 回答