co.occurance.count <- function(DF) {
code <- as.character(DF$code)
R <- as.data.frame(t(cbind(rbind(unique(code), unique(code)),
combn(code, 2))))
names(R) <- c("code1", "code2")
return(R)
}
tmp <- ddply(in.dat, .(ID), co.occurance.count)
out.dat <- as.data.frame(table(tmp[-1]))
Ugly but effective...
HTH,
Ista
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org
Many thanks for the solutions you have provided. You were right, I had
some flaw in my example. I was actually looking for the following
solution you gave
A <- table(in.dat)
Ared <- ifelse(A > 0, 1, 0)
out.dat <- ifelse(crossprod(A,Ared)>crossprod(Ared,A),crossprod(A,Ared),crossprod(Ared,A))
I like to thank Ista for the assymetric version of the solution. It
appears that his solution is faster for large data set (at least 1
million records). Can we make it symmetric like the one Jonathan did?
Thanks again for your time and help.
--
Mahbub Majumder
Graduate Student
Dept. of Statistics
Iowa State University
I think you can write this a little more simply (and efficiently) as:
pmax(crossprod(A, Ared), crossprod(Ared, A))
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
I appreciate your help.
Thanks.
--
Thanks for pmin() function. I used it as follows:
Ared <- pmin(A,1)
Is it faster than ifelse(A > 0, 1, 0)?
--