I'm sure there's a painfully easy solution to this, but given I'm new to R I'm a bit stumped.
I have a large dataset with the data structured accordingly.
v1
1 US2
2 L1_US24
3 US2_0
4 US24
5 US245
6 US245
7 US24 L
8 US3
What I'd like to do is create a categorisation column dependent upon the values in v1 like so:
v1 Cat
1 US2 1
2 L1_US24 2
3 US2_0 1
4 US24 2
5 US245 3
6 US245 3
7 US24 L 2
8 US3 4
Now if it was a binary choice it would be quite easy for I could use 'grepl' with 'ifelse' to assign the values accordingly. However I'm unsure whether that is an efficient way of doing it in a large dataset where the same values are contained in the columns.
Can anyone provide some advice on how to achieve the desired result?