Skip to content
Prev 326798 / 398502 Next

replace multiple values in vector at once

David is right, but it's trivial if x is a factor (which is the
default when you create character columns in a data frame).

(Note also how to use rep() properly -- read the docs: ?rep)

x <- factor(rep(LETTERS[1:3],e=3))
x
[1] A A A B B B C C C
Levels: A B C

levels(x) <- 1:3
x
[1] 1 1 1 2 2 2 3 3 3
Levels: 1 2 3

Cheers,
Bert
On Fri, Jul 12, 2013 at 3:05 PM, David Winsemius <dwinsemius at comcast.net> wrote: