s-news
[Top] [All Lists]

Re: problem in substring()

To: "'Nora Muda'" <noramuda@yahoo.com>, s-news@lists.biostat.wustl.edu
Subject: Re: problem in substring()
From: "Mario Cortina Borja" <M.Cortina@ich.ucl.ac.uk>
Date: Wed, 24 Jan 2007 09:44:12 -0000
In-reply-to: <958649.32857.qm@web61024.mail.yahoo.com>
References: <958649.32857.qm@web61024.mail.yahoo.com>
Thread-index: Acc/mUX74MKwKxk6SXu7/XAF6GPcZAAAiPLg

Dear Nora,

 

Try

 

as.numeric(substring( a, nchar(y[1])+1, nchar(y[1])+nchar(y[10])))

 

Best wishes,

 

Mario

 

Dr Mario Cortina Borja

Senior Lecturer in Statistics

Centre for Paediatric Epidemiology and Biostatistics

Institute of Child Health, University College London

M.Cortina@ich.ucl.ac.uk

Tel - 020 7905 2113

FAX - 020 7905 2381

 


From: s-news-owner@lists.biostat.wustl.edu [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Nora Muda
Sent: 24 January 2007 08:52
To: s-news@lists.biostat.wustl.edu
Subject: [S] problem in substring()

 

Dear S-Plus users,

 

I have problems in using substring ( ) function. My question may looked simple to all of you, since I am new to Splus. I have problems to get back my 2 digits number after did paste ( ) function. 

 

Let say I have 10 numbers.

 

>y <- c(1:10)

>a <- as.numeric(paste(y[1],y[10],sep=""))

$a:

[1] 110

 

then I want to separate it back apart;

>as.numeric(substring(a,1,1))

[1] 1

>as.numeric(substring(a,2,2))

[1]  1    <------------   suppose I want '10' not '1'

 

I noticed that substring( ) separate one string at a time, how to do if we want 2 strings as my example above?

 

Hopefully someone will help to answer my questions.

 

Thank you in advance.

 

--Nora.

 


Need a quick answer? Get one in minutes from people who know. Ask your question on Yahoo! Answers.

<Prev in Thread] Current Thread [Next in Thread>