| To: | <s-news@lists.biostat.wustl.edu> |
|---|---|
| Subject: | Re: switch keyword |
| From: | <Dario.Ciraki@ubs.com> |
| Date: | Tue, 9 Oct 2007 16:40:33 +0100 |
| In-reply-to: | <357352.46088.qm@web62003.mail.re1.yahoo.com> |
| References: | <357352.46088.qm@web62003.mail.re1.yahoo.com> |
| Thread-index: | AcgKgSEB99TQwiX2TYmd2RNreY9Q1QACMhrg |
| Thread-topic: | [S] switch keyword |
|
I assume you also wish to cover the cases where
your integer vector takes values of 20 and 50 exactly, as your specifications
would exclude them.
switch within an if loop would be slow if you wish to
recode large vectors, an efficient solution for your case can be to
use:
ifelse(x <= 20,1,0) + ifelse(x <= 50 & x >
20, 2,0) + ifelse(x >= 50,3,0)
From: s-news-owner@lists.biostat.wustl.edu [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of carol white Sent: 09 October 2007 15:09 To: s-news@lists.biostat.wustl.edu Subject: [S] switch keyword I have an integer vector that I want to convert to a categorical vector with values 1, 2, 3. If the value of an element of the integer vector < 20, then, the value of the corresponding element in the categorical vector will be 1 if the value of an element of the integer vector > 20 and < 50, then, the value of the corresponding element in the categorical vector will be 2 if the value of an element of the integer vector > 50, then, the value of the corresponding element in the categorical vector will be 3 can I do this by switch and how look forward to your feedback carol
Catch up on fall's hot new shows on Yahoo! TV. Watch previews, get listings, and more! Visit our website at http://www.ubs.com This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mails are not encrypted and cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments. UBS Limited is a company registered in England & Wales under company number 2035362, whose registered office is at 1 Finsbury Avenue, London, EC2M 2PP, United Kingdom. UBS AG (London Branch) is registered as a branch of a foreign company under number BR004507, whose registered office is at 1 Finsbury Avenue, London, EC2M 2PP, United Kingdom. UBS Clearing and Execution Services Limited is a company registered in England & Wales under company number 03123037, whose registered office is at 1 Finsbury Avenue, London, EC2M 2PP, United Kingdom. |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Réf. : switch keyword, gerald . jean |
|---|---|
| Next by Date: | Re: switch keyword, Padhye, Nikhil S |
| Previous by Thread: | Dumping Matrix/Data.Frame to Graphsheet?, Redfearn, Christian |
| Next by Thread: | Re: switch keyword, Padhye, Nikhil S |
| Indexes: | [Date] [Thread] [Top] [All Lists] |