[R] element-by-element comparison
ligges at statistik.tu-dortmund.de
Sun Oct 30 11:13:51 CET 2011
On 30.10.2011 04:51, Wendy wrote:
> I have a vector and a matrix. For example,
> A = [
> B = [
> 4 13
> 10 2
> 4 8];
> I am comparing A to each column of B using A>B[,ii], so the expected result
> C = [
> 1 0
> 0 1
> 0 0];
This list is about R rather than Matlab dialects.
gives logical values and, e.g.,
apply(A>B, 2, as.integer)
converts to integer.
> I am looking for a way to do this quickly instead of going through the for
> loop, but haven't had any luck yet? Any advice is appreciated.
> Thank you very much.
> View this message in context: http://r.789695.n4.nabble.com/element-by-element-comparison-tp3952301p3952301.html
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help