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.

In [22]:
leading.digit = function(x) {
    order_of_magnitude = floor(log10(x))
    floor(x/10^order_of_magnitude)
}
In [23]:
leading.digit(478.52)
Out[23]:
4
In [24]:
leading.digit(100)
Out[24]:
1
In [25]:
leading.digit(0.0000999999999)
Out[25]:
9

Notice that R functions for numerical variables automatically work entrywise for vectors.

In [26]:
x = c(0.01,289.3,35,0.00004000,0.5,678)
leading.digit(x)
Out[26]:
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
In [ ]: