[R] create matrix from comparing two vectors

2007-06-26 Thread Van Campenhout Bjorn
hi all, sorry for this basic question, I think I know I should use ?apply, but it is really confusing me... I want to create a matrix by comparing two vectors. Eg: test-seq(1:10) fac-c(3,6,9) and i want to end up with a 10*3 matrix with a boolean that tests if testfac, so something like: 1

Re: [R] create matrix from comparing two vectors

2007-06-26 Thread Benilton Carvalho
outer(test, fac, ) -b On Jun 26, 2007, at 2:13 PM, Van Campenhout Bjorn wrote: hi all, sorry for this basic question, I think I know I should use ? apply, but it is really confusing me... I want to create a matrix by comparing two vectors. Eg: test-seq(1:10) fac-c(3,6,9) and i want

Re: [R] create matrix from comparing two vectors

2007-06-26 Thread Dimitris Rizopoulos
try this: test - 1:10 fac - c(3, 6, 9) outer(test, fac, ) * 1 I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax:

Re: [R] create matrix from comparing two vectors

2007-06-26 Thread Horace Tso
In case you really want to use the apply variety, here is another one, sapply(fac,function(x)ifelse(test/x1, 1, 0)) H. Van Campenhout Bjorn [EMAIL PROTECTED] 6/26/2007 11:13:14 AM hi all, sorry for this basic question, I think I know I should use ?apply, but it is really confusing me... I