Reputation: 33
I have a large df with values in a column with the sequence pattern: seq(1,3000,10).
I need to change every value in the column so that
1 = 1
11 = 2
21 = 3
31 = 4
41 = 5
The order of these numbers are jumbled in places, therefore I need to define that every 1 is converted to 1, 11 to 2, 21 to 3, 31 to 4 and so on for thousands of numbers with this sequence pattern.
Upvotes: 1
Views: 55
Reputation: 35554
Example
x <- seq(1, 100, by = 10)
# [1] 1 11 21 31 41 51 61 71 81 91
You can use %/%
:
x %/% 10 + 1
# [1] 1 2 3 4 5 6 7 8 9 10
Upvotes: 2