s-news
[Top] [All Lists]

substring with different formats

To: <s-news@lists.biostat.wustl.edu>
Subject: substring with different formats
From: "Boylan, Richard" <rboylan@bus.olemiss.edu>
Date: Mon, 9 Jul 2001 22:16:04 -0500
Thread-index: AcEI7qd2rQL4AFjDRliDSew11wvvCQ==
Thread-topic: substring with different formats
 
I posted a question regarding extending the function substring.   I will repeat my question
and put the only response that I received.
 
Q:
I was wondering if anyone had extended the * substring * command to allow for something
like this:
 
x <- c("Alabama, Northern", "Alaska", "Georgia, Southern")
unpaste( x, ",")
 
[[1]] "Alabama"  "Alaska"  "Georgia"
[[2]] "Northern" "NA"  "Southern"
 
In other words, extending unpaste to the case in which the separtor does not exist for all
observations.
 
A: (S.D. Byers)
In perl there is a function called qw. It does exactly that. I wrote an
Splus equivalent some time ago:

qw <- function(x) { unlist(string.break.line(translate(x, " ", "\n"))) }

This mandates you  have the translate function but  you could probably
rewrite to  get around that.  Or just use the  string.break.line thing
more directly.

Example:

S+> qw("Monday Tuesday Wednesday Thursday Friday Sauturday Sunday")
        1         2           3          4        5           6        7
 "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Sauturday" "Sunday"


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