[R] creating conditional list of elements

murali.menon at uk.abnamro.com murali.menon at uk.abnamro.com
Thu Mar 29 14:56:15 CEST 2007


John,

Thanks, that works nicely. Didn't know about 'get'. 

Onwards and upwards! :-)
Cheers,
Murali




"John James" <jjames at mango-solutions.com> 
29/03/2007 12:40

To
<murali.menon at uk.abnamro.com>
cc

Subject
RE: [R] creating conditional list of elements






Murali

If sm is your orginal matrix
# such that 
> sm[sm$Enabled,]$Signal
[1] "bar_signal" "cif_signal" 

# and
bar_signal <- matrix(rnorm(100), nrow=5, ncol=20)
cif_signal <- matrix(rnorm(60), nrow=12, ncol=5)

# then...
sapply(sm[sm$Enabled,]$Signal, function(x){NROW(get(x))})
bar_signal cif_signal 
         5         12

Hope this helps

John James
Mango Solutions

-----Original Message-----
From: murali.menon at uk.abnamro.com [mailto:murali.menon at uk.abnamro.com] 
Sent: 29 March 2007 11:40
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] creating conditional list of elements

Sorry to plague the list, but I think I got the answer. The following 
would do:

> signalList <- list(tradingRules$Signal[tradingRules$Enabled]) [[1]]
> length(signalList)
[1] 2

Now my problem is shifted: I have the Signal column in the original data 
frame referring to actual 
matrices previously created in R. That is, bar_signal and cif_signal are 
extant matrices. What I 
need is the minimum number of rows in these matrices, so what I plan to do 

is:

> n <- min(sapply(signalList, NROW))

but this doesn't work (it returns 1, but I have 2800 rows in each of 
bar_signal and cif_signal, so I should
get 2800)

Is there a smart way to do this? And is there a way to tell R that the 
entries in the Signal column 
of tradingSignal are the names of objects?

Thanks,
Murali



Murali Menon/GB/ABNAMRO/NL 
29/03/2007 11:13

To
r-help at stat.math.ethz.ch
cc

Subject
creating conditional list of elements





Folks,

I have a matrix as follows (first column is the rownames, first row is the 

columnnames)

Rule    Enabled Signal
Foo     False           foo_signal
Bar     True            bar_signal
Gum     False           gum_signal
Cif     True            cif_signal

I would like to create a list of only those signals whose 'enabled' flag 
is True. So in the above 
case I should end up with

signalList = bar_signal, cif_signal

Likewise, if the enabled flags were all set to False, then signalList 
should be an empty list.

What's a good way to achieve this, please?

Thanks,

Murali



---------------------------------------------------------------------------
This message (including any attachments) is confidential and...{{dropped}}

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





---------------------------------------------------------------------------
This message (including any attachments) is confidential and...{{dropped}}



More information about the R-help mailing list