On Wed, 5 Jun 2002, Arjun Bhandari wrote:
> Hi,
>
> I am trying to do the following but cannot find appropriate functions in
> splus which help one do it.
>
> I have a vector of strings, say mymatrix.
Strings? More likely a character vector, but both exist in S-PLUS 5.x and
6.x.
> I want to create another vector which holds all the combinations of
> different strings apart from the one where the indices are the same. so
if
> there are three strings in mymatrix say "abc", "def", "ghi"
>
> I want mycombination to hold strings: "abc;def", "abc;ghi","def:ghi"
>
> Can anyone let me know which string functions to use and if there is a
list
> of string functions available to be used with splus. The only ones I am
> aware of are substing, nchar.
Those are character functions. The one you are missing most is `paste'.
There are lists in all good books on S.
I suspect there is a typo, and what you actually want is
> x <- c("abc", "def", "ghi")
> X <- outer(x, x, function(x, y) paste(x,y,sep=";"))
> X[col(X) > row(X)]
[1] "abc;def" "abc;ghi" "def;ghi"
--
Brian D. Ripley, ripley@stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
|