0

I've read the previous posts and understand that my question is answered in different ways but I need to verify if I am on the right track please. I have a column in my data that ranges form 0.00012 to 1452. My goal is to rescale or normalize this column into a factor column ranging from 1 to 20 that are all discrete numbers then round to whole numbers. I have read this post Scale a series between two points and also this R- Normalizing certain columns from 0 to 1 with values equal to 0 that help but I can't get my final result. A sample of the data is as follows:

df_sample <- data.frame(performance_time= c(0.00012,0.12,3.45,12.65,5.8,145,782.45,1452,92.78,101.32))

Output of interest should be a rescaled column of C ranging from 1 to 20 and all discreet values. It would be great if I can perform it using dplyr.

Thank you for your help in advance.

Alex
  • 245
  • 1
  • 7
  • Not sure what "numbers that are the closest to their origin with decimals" means. Do you want to rescale between 1 and 20, then round to whole numbers? If so it's `x <- (x - min(x))/(max(x) - min(x)); x <- 1 + 19*x; x <- round(x)` – dash2 Mar 20 '22 at 22:13
  • @dash2 that's what I meant, sorry about the confusion. Thank you – Alex Mar 20 '22 at 22:14

0 Answers0