idmatch:

Usage Arguments Examples

Usage

1
idmatch(m1, m2, id.col1, id.col2 = id.col1)

Arguments

m1
m2
id.col1
id.col2

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (m1, m2, id.col1, id.col2 = id.col1) 
{
    flag = !is.na(m1[, id.col1])
    m1 = m1[flag, ]
    flag = !is.na(m2[, id.col1])
    m2 = m2[flag, ]
    M1 = NULL
    if (sum(duplicated(m1)) > 0) 
        stop("Duplicate ids detected in m1")
    if (sum(duplicated(m2)) > 0) 
        stop("Duplicate ids detected in m2")
    for (i in 1:nrow(m1)) {
        flag = duplicated(c(m1[i, id.col1], m2[, id.col2]))
        if (sum(flag > 0)) {
            if (is.data.frame(m1)) {
                if (!is.null(dim(M1))) 
                  M1 = rbind(M1, as.data.frame(m1[i, ]))
                if (is.null(dim(M1))) 
                  M1 = as.data.frame(m1[i, ])
            }
            if (!is.data.frame(m1)) {
                if (!is.null(dim(M1))) 
                  M1 = rbind(M1, m1[i, ])
                if (is.null(dim(M1))) 
                  M1 = matrix(m1[i, ], nrow = 1)
            }
        }
    }
    M2 = NULL
    for (i in 1:nrow(m2)) {
        flag = duplicated(c(m2[i, id.col2], m1[, id.col1]))
        if (sum(flag > 0)) {
            if (is.data.frame(m2)) {
                if (!is.null(dim(M2))) 
                  M2 = rbind(M2, as.data.frame(m2[i, ]))
                if (is.null(dim(M2))) 
                  M2 = as.data.frame(m2[i, ])
            }
            if (!is.data.frame(m2)) {
                if (!is.null(dim(M2))) 
                  M2 = rbind(M2, m2[i, ])
                if (is.null(dim(M2))) 
                  M2 = matrix(m2[i, ], nrow = 1)
            }
        }
    }
    m = cbind(M1[, id.col1], M1[, -id.col1], M2[, -id.col2])
    m
  }

musto101/wilcox_R documentation built on May 23, 2019, 10:52 a.m.