Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Matrix of "correlation" in R

$
0
0

I'm sure this question has been asked, but I'm not sure what terms to search. I want to generate a table/matrix/dataframe that shows, for every file, whether the md5sum of that file is equal to the md5sum of every other file. The code below generates some toy data and expected result. Since this code uses a for loop, I'm going to assume this is not the best approach.

options(stringsAsFactors = FALSE)

name <- letters[1:9]
code <- c("1", "2", "2", "3", "4", "5", "2", "6", "6")
pairs <- data.frame(name = name, code = code)

for (i in 1:length(name)) {
    for (j in 1:length(name)) {
        if (i == 1 & j == 1) {
            data <- setNames(
                data.frame(
                    matrix(ncol = length(name), nrow = length(name)), 
                    row.names = name
                ), 
                name
            )
        }
        data[i, j] <- as.numeric(code[i] == code[j])
    }
}

Is there a function that will perform this analysis, or a better way of doing this?


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>