?dist
Rule 1: Do not try to do it by yourself. Assume that a function already
exists to do what you want unless you know otherwise. Then use R's search
and help capabilities to find it (it may be in an external package on CRAN).
In this case, help.search("distance") would have given you dist.
-- Bert Gunter
Genentech