Skip to content
Back to formatted view

Raw Message

Message-ID: <CA+dpOJ=8WZqsJ9MJ-2nUpgNQ3jdu4dOQ0qKfX45ex5JYuNubZg@mail.gmail.com>
Date: 2013-02-14T11:43:25Z
From: Christofer Bogaso
Subject: Looking for an easy way to change the names of a vector

Hello again,

Let say I have following vector (this is basically a snap of very large vector):


Data <- 1:8
names(Data) <- c("ada", "fsdfs", "asd fd", "asdsa", "dsada", "asasad",
"adas asdad", "aasaa")
Data

Now I want to change the names according to following rule:

1. If there is any space then replace that space by "-"
2. Otherwise add "-XXX" at the last to each name

Therefore the names will be:

c("ada-XXX", "fsdfs-XXX", "asd-fd", "asdsa-XXX", "dsada-XXX",
"asasad-XXX", "adas-asdad", "aasaa-XXX")


Can somebody point me some direct way for that?

Thanks for your help