As usual, the list is wonderfully helpful and informatve. I've
been inundated with replies. Again, as always, I'm mystified by the
number of ways people come up with solutions. It's grand!
My original query was:
> I have a very simple operation that I'd like to vectorize.
> However, I haven't figured out how to do it. Being an unrepentant Fortran
> 77 hacker, this vectorization stuff sometimes escapes me. Here's what I'm
> after: within a data frame, I want to know what columns contain negative
> values and I want the results returned as a logical vector.
>
> This works, but uses looping:
>
> test <- logical(0)
> for (i in 1:100)
> {
> test[i] <- all(df[,i] < 0)
> }
>
> Surely there's a way to vectorize this. Please, somebody rescue
> me from my ignorance!
So, without further ado, here are the various answers from all of
you:
|