Reputation: 873
I have a numeric vector as below:-
num <- c(1.2,2.3,2.4,4.6,1.43,8.99,7.12,6.77,......)
This vector is quite a big vector.
What I want to do is to replace all values between 1 and 2 with 1, values between 2 and 3 with 2 and so on.
num_scaled <- c(1,2,2,4,1,8,7,6,.....)
Is there any simpler way to do this in R? A function?
Upvotes: 1
Views: 125
Reputation: 13372
num <- c(1.2,2.3,2.4,4.6,1.43,8.99,7.12,6.77)
num_scaled <- trunc(num)
gives you:
> num_scaled
[1] 1 2 2 4 1 8 7 6
Upvotes: 1