# Re: [R] create matrix from comparing two vectors

From: Horace Tso <Horace.Tso_at_pgn.com>
Date: Tue, 26 Jun 2007 13:01:13 -0700

In case you really want to use the apply variety, here is another one,

sapply(fac,function(x)ifelse(test/x<1, 1, 0))

H.

>>> "Van Campenhout Bjorn" <bjorn.vancampenhout_at_ua.ac.be> 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 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 test<fac, so something like:

1 1 1
1 1 1
0 1 1
0 1 1
0 1 1
0 0 1
0 0 1
0 0 1
0 0 0
0 0 0

I can't find the solution without using a loop...

B

[[alternative HTML version deleted]]

R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 26 Jun 2007 - 20:22:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 26 Jun 2007 - 20:34:02 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.