s-news
[Top] [All Lists]

sapply question

To: s-news@wubios.wustl.edu
Subject: sapply question
From: Eric yang <yang_eric9@yahoo.com>
Date: Mon, 13 Mar 2006 05:50:11 -0800 (PST)
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=R6eBBSq32Wjhfozr/fk6YuKRE0bkH/2Rmb20HoSxd1k5LFSWCHt7bovRBoye0wqjLSrGYicgWeiazsOskhyTUDJm7ZKXNtD2Iv9vcJPgn+OkjlrIMs3iRZuLsD474UMk5qJEfgh+iOGwClF3XOEpvbSuYyMZLmuZuYATs7QftqY= ;
 
Dear members,
 
I have a rather simple problem which is consequence of me trying to make my programming more efficient. Suppose, for examlpe, I want to produce this
 
[1] "A is letter"       "B is letter"       "C is letter"       "D is letter"     
[5] "E the last letter"
I can write the following:
 
 x <- LETTERS[1:5]
sapply(seq(along=x), function(count, my.letter) paste(my.letter[count], if(count<5) " is" else " the last"," letter" , sep=""), x)
 
Is it possible to write this without specifying two variables in the function call, e.g. can I do the above using
 
sapply(x, function(my.letter), paste(my.letter, ...
 
but how do I do the "if" part of the paste statement.
 
Thanks in advance of any help.
 
Eric


Yahoo! Mail
Bring photos to life! New PhotoMail makes sharing a breeze.
<Prev in Thread] Current Thread [Next in Thread>