s-news
[Top] [All Lists]

Re: select vector names

To: "Heymans, MW" <mw.heymans@vumc.nl>
Subject: Re: select vector names
From: Tony Plate <tplate@blackmesacapital.com>
Date: Thu, 11 May 2006 09:12:32 -0600
Cc: s-news <s-news@lists.biostat.wustl.edu>
In-reply-to: <B8CF0F16EE1E1B42854D9ACCEB60686427400B@vumc-mb01.vumc.nl>
References: <B8CF0F16EE1E1B42854D9ACCEB60686427400B@vumc-mb01.vumc.nl>
User-agent: Mozilla Thunderbird 1.0.5 (Windows/20050711)
Here's how you can do it using regular expression substitution:

> x <- c("FA", "WLV=2", "WLV=3", "WLV=4", "TS", "BAE", "BH", "WKZ", "RDQB", "gr=1", "gr=2", "gr=3")
> sort(unique(gsub("=.*","",x)))
[1] "BAE"  "BH"   "FA"   "RDQB" "TS"   "WKZ"  "WLV"  "gr"
>

(According to its documentation, gsub() in S-PLUS is intended to provide partial compatibility with the R function gsub())

-- Tony Plate

Heymans, MW wrote:
Dear all,
I have this vector of names: [1] "FA" "WLV=2" "WLV=3" "WLV=4" "TS" "BAE" "BH" "WKZ" "RDQB" "gr=1" "gr=2" "gr=3" "gr=4" "gr=5" "gr=6"
[16] "gr=7"

and I want to change it to (same order, but without the factor extensions):

[1] "FA" "WLV" "TS" "BAE" "BH" "WKZ" "RDQB" "gr"
help is appreciated (I got stuck in the regexpr functions).
regards, Martijn


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