Here is my quick solution - I'm sure you will get better ones.
logvec<-is.element(1:100,unique(col(df)[df<0]))
good luck.
Michael Conklin
************************************************************
From: "CHASALOW, SCOTT [AG/2165]" <SCOTT.CHASALOW@cereon.com>
Kim,
Here's one way to add to the many I'm sure you've received:
colSums(dfr < 0) == nrow(dfr)
This assumes, as I guess from your example, you want columns
containing *only* negative values.
Cheers,
Scott
Cereon Genomics
Scott.Chasalow@cereon.com
************************************************************
From: Don MacQueen <macq@llnl.gov>
I'm going to assume all columns in your dataframe are numeric, and that
you're using Splus 5.1 on unix or Splus 2000 in Windows. More accurately,
using a version that has the rowSums() function.
Here's an example:
> foo <- data.frame(x=.5-runif(10),y=.2-runif(10),z=1:10)
> foom <- as.matrix(foo) <0
> colSums(foom) > 0
x y z
T T F
Or, as a one-liner
test <- rowSums( as.matrix(df) < 0) > 0
Or, if you don't have a version with colSums()
> apply(foom,2,FUN=function(x) sum(x)>0)
x y z
T T F
In which case, the oneliner is
test <- apply(as.matrix(df) < 0, 2, FUN=function(x) sum(x)>0)
Note that the assumption that the data frame is entirely numeric is crucial.
Yet another version is
sapply(foo,FUN=function(x) sum(x<0)>0)
This version seems to work even with columns that have character data,
since the following do not result in error messages:
> 'a' < 0
[1] F
> 'a' > 0
[1] T
Note that apply(), sapply(), and colSums() are all functions that have the
looping built in. Saving us the trouble of writing the loop explicitly.
-Don
************************************************************
Whew! Thanks again to every, single one of you. What a great
group!
Kim Elmore, [N5OP, PP ASMEL/Glider 2232456]
"All of Meteorology is divided into three parts: Yes, No and Maybe. The
greatest of these is Maybe." -- The original Latin appears to be garbled.
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|