简体   繁体   中英

R range distance - is there an existing function?

Very simple one here - does anyone know if there's an existing single function that returns the absolute distance between the range of a vector? ie:

tmp <- rnorm(100)
range(tmp) # -2.659657  2.853642
#This line:
range(tmp)[2] - range(tmp)[1] # 5.513299

Is there already something that just does that final line? I've looked for various things but it occurs to me that it might have a specific name in maths that I've not stumbled upon yet. Thanks!

您可以使用diff()函数:

diff(range(tmp)) # 5.513299

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM