R lets you make your own functions. Here is an example. I will define a function that converts a number like 478.53 to its leading digit, in this case 4.
leading.digit = function(x) {
order_of_magnitude = floor(log10(x))
floor(x/10^order_of_magnitude)
}
leading.digit(478.52)
leading.digit(100)
leading.digit(0.0000999999999)
Notice that R functions for numerical variables automatically work entrywise for vectors.
x = c(0.01,289.3,35,0.00004000,0.5,678)
leading.digit(x)