How to convert the x below to into a vector like y?

```
x <- ["a", "b", "b", "c", ...]
y <- [1, 2, 2, 3, ...]
```

**UPDATE:**

I end up with:

```
levels(x) <- 1:length(levels(x))
```

Skip to content
# Solved – How to convert a vector of enumerable strings into a vector of numbers?

r

How to convert the x below to into a vector like y?

```
x <- ["a", "b", "b", "c", ...]
y <- [1, 2, 2, 3, ...]
```

**UPDATE:**

I end up with:

```
levels(x) <- 1:length(levels(x))
```

## Best Answer

Here is a possibility, very similar than that of @Roman Lustrik, but just a little bit more automatic.

Say that

Then

makes the job: