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
|