Skip to content

Instantly share code, notes, and snippets.

@kuniyoshi
Created February 22, 2014 08:14
Show Gist options
  • Save kuniyoshi/9150396 to your computer and use it in GitHub Desktop.
Save kuniyoshi/9150396 to your computer and use it in GitHub Desktop.
Calculate Spearman's cor.
portal <- read.table("portal.log", sep="¥t", header=TRUE)
portal.sub <- portal[sample(length(portal[,1]), 9000), ]
ip.order <- data.frame(median=tapply(portal.sub$us, portal.sub$ip, median))
ip.order$order <- order(ip.order)
portal.sub$ip.o <- ip.order[portal.sub$ip, 2]
with(portal.sub, cor(us, ip.o, method="spearman"))
# 0.5039202
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment