How can i rescale every column in my data frame to a 0-100 scale? (in r)

后端 未结 2 746
无人共我
无人共我 2021-02-09 05:10

i am trying to get all the colums of my data frame to be in the same scale..

right now i have something like this... where a is on a 0-1 scale b is on a 100 scale and

2条回答
  •  难免孤独
    2021-02-09 06:04

    My experience is that this is still unanswered, what if one of the columns had a -2, the current answer would not produce a 0-100 scale. While I appreciate the answer, when I attempted it, I have variables that are -100 to 100 and this left some negative still?

    I have a solution in case this applies to you:

    rescale <- function(x) (x-min(x))/(max(x) - min(x)) * 100
    dat <- rescale(dat)
    

提交回复
热议问题