Skip to content
Prev 275903 / 398506 Next

element-by-element comparison

The recycling rule should apply here (see 'An Introduction to R', Sec. 
5.4.1; and ?Comparison, under 'Value').

x <- -5:5
A <- cbind(x, x, x)
vec <- numeric(length(x))
A > vec             ### recycling
apply(A,2,`>`,vec)  ### using apply

vec <- numeric(11) + 3; vec[1] <- -6
A > vec             ### recycling
apply(A,2,`>`,vec)  ### using apply

It should be faster than apply, but then apply seems much clearer.


Regards,
Enrico


Am 30.10.2011 08:55, schrieb Jim Lemon: