构造元素之间关系的对称矩阵

时间:2016-12-16 10:50:29

标签: r

有一个矩阵:

DefaultUncaughtExceptionHandler

我想计算infor <- cbind(c("1st","2nd","3rd","4th","5th","6th"), c("a;b;c","c;d;e;f","a;c;d","b;g;h","b;d;e","e;h")) infor [,1] [,2] [1,] "1st" "a;b;c" [2,] "2nd" "c;d;e;f" [3,] "3rd" "a;c;d" [4,] "4th" "b;g;h" [5,] "5th" "b;d;e" [6,] "6th" "e;h" 中每两个元素之间的重叠,并构造一个像这样的对称矩阵:

infor[, 1]

然后我建立了两个矩阵aa和bb:

> result
    1st 2nd 3rd 4th 5th 6th
1st   3   1   2   1   1   0
2nd   1   4   2   1   2   1
3rd   2   2   3   1   1   0
4th   1   1   1   3   1   1
5th   1   2   1   1   3   1
6th   0   1   0   1   1   2

我想知道是否有一个可以用来实现我的目标的功能,就像

一样
> aa <- matrix(rep(infor[, 2], dim(infor)[1]), nrow=dim(infor)[1])
> aa
     [,1]      [,2]      [,3]      [,4]      [,5]      [,6]     
[1,] "a;b;c"   "a;b;c"   "a;b;c"   "a;b;c"   "a;b;c"   "a;b;c"  
[2,] "c;d;e;f" "c;d;e;f" "c;d;e;f" "c;d;e;f" "c;d;e;f" "c;d;e;f"
[3,] "a;c;d"   "a;c;d"   "a;c;d"   "a;c;d"   "a;c;d"   "a;c;d"  
[4,] "b;g;h"   "b;g;h"   "b;g;h"   "b;g;h"   "b;g;h"   "b;g;h"  
[5,] "b;d;e"   "b;d;e"   "b;d;e"   "b;d;e"   "b;d;e"   "b;d;e"  
[6,] "e;h"     "e;h"     "e;h"     "e;h"     "e;h"     "e;h"    
> bb <- t(aa)
> bb
     [,1]    [,2]      [,3]    [,4]    [,5]    [,6] 
[1,] "a;b;c" "c;d;e;f" "a;c;d" "b;g;h" "b;d;e" "e;h"
[2,] "a;b;c" "c;d;e;f" "a;c;d" "b;g;h" "b;d;e" "e;h"
[3,] "a;b;c" "c;d;e;f" "a;c;d" "b;g;h" "b;d;e" "e;h"
[4,] "a;b;c" "c;d;e;f" "a;c;d" "b;g;h" "b;d;e" "e;h"
[5,] "a;b;c" "c;d;e;f" "a;c;d" "b;g;h" "b;d;e" "e;h"
[6,] "a;b;c" "c;d;e;f" "a;c;d" "b;g;h" "b;d;e" "e;h"

> Overlaps <- function(a, b){
    spliteA <- strsplit(a, ";")
    spliteB <- strsplit(b, ";")
    score <- length(intersect(spliteA, spliteB))
    return(score)
  }

顺便说一下,我不喜欢循环。 ^^

1 个答案:

答案 0 :(得分:1)

您可以尝试:

<module>
    <web>
        <web-uri>newApp.war</web-uri>    // changed from myApp to newApp
        <context-root>newApp</context-root>  
    </web>
</module>