Last active
May 2, 2017 20:38
-
-
Save WillForan/5a09e66f998188a3e1b20ea4776454e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
#options(stringsAsFactors = F) | |
#z1=read.delim(file='/Users/jalbrzikowskime/gordon_ci.txt',header=F) | |
#z2=read.delim(file='/Users/jalbrzikowskime/infomap_luna_denoise_t9.txt',header=F) | |
# fake data | |
d<-data.frame( | |
id=c(1,2,3,4,5,6,7,8,9,10), | |
z1=c(1,1,1,3,3,3,3,2,2,1), | |
z2=c(5,5,5,5,4,4,4,8,8,4) | |
) | |
# function to find the index of a max value (and pick the first if there is mroe than one) | |
firstbestmatch <- function(x) which.max(x) %>% first() | |
# count overlap between z2 and z1 | |
matchtable=table(d$z2,d$z1) | |
# get best fit based on highest overlap (count) | |
bestfit<-apply(FUN=firstbestmatch,MARGIN=1,matchtable) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment