[R] Populate matrix from data.frame

2007-06-28 Thread Andrej Kastrin
Dear all, I have a data frame a - data.frame(cbind(x=c('a','a','a','b','c'), y=c('a','b','c','d','e'),z=c(1,2,3,4,5))) a x y z 1 a a 1 2 a b 2 3 a c 3 4 b d 4 5 c e 5 and a matrix mm - matrix(0,5,5) colnames(mm) - c('a','b','c','d','e') rownames(mm) - c('a','b','c','d','e') mm a b c d e

Re: [R] Populate matrix from data.frame

2007-06-28 Thread Prof Brian Ripley
On Thu, 28 Jun 2007, Andrej Kastrin wrote: Dear all, I have a data frame a - data.frame(cbind(x=c('a','a','a','b','c'), y=c('a','b','c','d','e'),z=c(1,2,3,4,5))) a x y z 1 a a 1 2 a b 2 3 a c 3 4 b d 4 5 c e 5 and a matrix mm - matrix(0,5,5) colnames(mm) - c('a','b','c','d','e')

Re: [R] Populate matrix from data.frame

2007-06-28 Thread Patrick Burns
You need some caution with Brian's solution as it depends on the matrix being in the same order as the factors in the data frame. a - data.frame(cbind(x=c('a','a','a','b','c'), y=c('a','b','c','d','e'),z=c(1,2,3,4,5))) mm - matrix(0,5,5) colnames(mm) - c('a','b','c','d','e') rownames(mm) -