How about something like:
paste(x, rep(c('is', 'the last'), c(length(x)-1, 1)), 'letter')
Patrick Burns
patrick@burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
Eric yang wrote:
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
<http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=39174/*http://photomail.mail.yahoo.com>
makes sharing a breeze.
|