Skip to content

Instantly share code, notes, and snippets.

@darokun
Created August 16, 2021 14:27
Show Gist options
  • Save darokun/b32c0373027b8e57fb8ab59b9ecfcc5b to your computer and use it in GitHub Desktop.
Save darokun/b32c0373027b8e57fb8ab59b9ecfcc5b to your computer and use it in GitHub Desktop.
# log_scale_exercises.R
format(1*10^-4, scientific = FALSE) # starting point: 1*10^-4 = 1e-04 = 0.0001
format(1*10^-3, scientific = FALSE) # ending point: 1*10^-3 = 1e-03 = 0.001
x <- seq(0.0001:0.001, by = 0.0001, length.out = 10) # 10 datapoints ascending from 0.0001 to 0.001
format(x, scientific = FALSE) # 0.0001, 0.0002, 0.0003, [...], 0.0008, 0.0009, 0.001
format(x, scientific = TRUE) # the same, but in scientific notation: 1e-04, 2e-04, 3e-04, [...], 8e-04, 9e-04, 1e-03
plot(x, xlim = c(0, 10), ylim = c(0.0001, 0.001), pch = 20, log = "y") # plot log scale on y axis, (intervals are not equally spaced)
plot(x, xlim = c(0, 10), ylim = c(0.0001, 0.001), pch = 20) # plot linear scale, (equally spaced intervals)
format(median(x[1:9]), scientific = TRUE) # middle point between 0.0001 and 0.001 in scientific notation: 5e-04 = 5*10^-4
format(median(x[1:9]), scientific = FALSE) # middle point between 0.0001 and 0.001 without scientific notation: 5e-04 = 5*10^-4 = 0.0005
format(1*10^-3.5, scientific = FALSE) # this results in 0.0003162278 and it's not the middle point between 0.0001 and 0.001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment