Skip to contents

r1sd allows you to rescale a numeric vector such that the ensuing output has a mean of 0 and a standard deviation of 1.

Usage

r1sd(x, na = TRUE)

Arguments

x

a numeric vector

na

what to do with NAs in the vector. Defaults to TRUE (i.e. passes over the missing observations)

Value

The function returns a numeric vector rescaled with a mean of 0 and a standard deviation of 1.

Details

This is a convenience function since the default rescale() function has some additional weirdness that is not welcome for my use cases. By default, na.rm is set to TRUE.

Examples


x <- rnorm(100)
r1sd(x)
#>   [1]  0.8589857352  0.6882792081 -0.3820161132 -0.2185607108 -2.3581866933
#>   [6] -1.1186076412 -0.9259636957  0.3993068214 -0.9705208235  0.9448918531
#>  [11] -1.9134339921  0.5798526209  0.6713547170  0.2153457412  1.3869096436
#>  [16]  0.3956947758 -0.4787230015  0.4141902533 -0.8131107521 -0.9124984890
#>  [21]  1.7734287396  1.3392256447  0.1729591211 -1.4489497087 -0.0413043116
#>  [26]  0.0220676683 -2.2579591760 -0.7365099747 -1.7214374886  0.9269118133
#>  [31]  0.2402823685 -1.5983065925  0.1540897909  0.4292600416  0.5623382525
#>  [36]  0.9417246305  0.7862868975  0.4378974028  0.5348330059  1.3801393606
#>  [41] -0.0601846493  0.0949865211  1.2914664780 -0.0007232612  0.9247860528
#>  [46] -0.1117526441 -0.5317138969 -0.1530381957  0.8195438764 -1.0799893600
#>  [51]  0.2095907871 -0.2415049796  2.6475450451 -1.0827106024 -0.3501653160
#>  [56]  0.2515200939  1.9588504804 -0.2365637631  0.6123825135 -1.9958963302
#>  [61]  0.3751642922  0.9637732620  0.4935186982  0.1102981212 -0.0458281813
#>  [66]  0.0081144400 -2.4718601906  0.3977882087  1.1481818390  1.4765321954
#>  [71] -0.4463775814  1.2445406548 -0.7944924161 -1.4013223523  1.2760452552
#>  [76] -0.5366643254  0.0709421095 -1.0050927198  1.3207408527  1.0405286073
#>  [81]  0.4652549313 -0.0473292065 -0.6480720990  0.9625997253 -1.4998238910
#>  [86] -0.8196351690 -1.2349042335  0.8690667709 -0.6636137487 -0.9215064628
#>  [91] -0.2838803156 -0.1382895314 -0.1508800263  1.0792471933 -0.8381494592
#>  [96]  0.5004442955 -0.0965475607 -1.6511651186  0.5083293670  0.0577279770