It is not exactly vectorization but you do this operation with the
"apply" function which applies a function to subsections of an array.
If I recall correctly it would look like
apply( as.matrix(df), 2, function(x) any(x < 0) ) # 2 indicates apply to
columns
> df <- as.data.frame( matrix( rnorm(10000, mean = 3), nrow = 1000 ) )
> apply( as.matrix( df ), 2, function(x) any( x < 0 ) )
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
TRUE TRUE TRUE FALSE TRUE TRUE FALSE FALSE TRUE TRUE
If you want to apply to rows of a matrix you use 1 as the second
argument.
BTW, I think from your description you wanted "any", not "all" in the
function.
|