Understanding `scale` in R

后端 未结 4 863
日久生厌
日久生厌 2020-12-12 15:50

I\'m trying to understand the definition of scale that R provides. I have data (mydata) that I want to make a heat map with, and there is a VERY st

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-12 16:13

    log simply takes the logarithm (base e, by default) of each element of the vector.
    scale, with default settings, will calculate the mean and standard deviation of the entire vector, then "scale" each element by those values by subtracting the mean and dividing by the sd. (If you use scale(x, scale=FALSE), it will only subtract the mean but not divide by the std deviation.)

    Note that this will give you the same values

       set.seed(1)
       x <- runif(7)
    
       # Manually scaling
       (x - mean(x)) / sd(x)
    
       scale(x)
    

提交回复
热议问题