Born in Bressay, Shetland, Scotland, Sir Robert Hamilton was the son of Rev. Zachary Macaulay Hamilton and his first wife Anne Irvine. He was educated at Grammar School. Robert was educated at University and King's College, Aberdeen, where he graduated MA in March 1854. In 1855, he migrated to London and entered the civil service as a temporary clerk at the war office. In the same year he was sent to the Crimea as a clerk in the commissariat department. In 1857, he was employed in the office of works, and in 1861 he was selected to take charge of the finance of the education department, the work of which was then rapidly growing in bulk and complexity. In 1869, on Lord Lingen's recommendation, Hamilton was appointed to the yet more difficult post of accountant to the board of trade, and in this capacity he successfully reorganised the board's financial department ; from 1872 to 1878 he was assistant-secretary to the board of trade. In 1872, he was appointed assistant-secretary and in 1874 secretary of Playfair's civil service inquiry commission ; in this capacity he spent some time at Dublin Castle with a view to its reorganisation. In 1878, he became accountant-general of the navy, and was the first to simplify the naval estimates so as to make them intelligible to the public. In 1879 he was appointed a member of The Earl of Carnarvon's royal commission on colonial defenses, and in May 1882 he was made permanent secretary to the admiralty. On the murder of Thomas Henry Burke in that month, Hamilton was lent by the admiralty for two successive periods of six months each to the Irish government as under-secretary of state for Ireland. He was then made permanent under-secretary and C.B. ; on 12 January 1884 he was created K.C.B., and in the following year honorary LL.D. of Aberdeen. While in Ireland, Hamilton became convinced of the advisability of home rule from an administrative point of view, and he is said to have had some share in influencing both his chief, Earl Spencer, and W. E. Gladstone in the same direction. The persistent rumour that he drafted Gladstone's first home rule bill in 1886 was quite incorrect, but his sympathies with home rule were naturally regarded as a cause of his removal from the under-secretaryship in November 1886 by the conservative ministry which had succeeded the liberal ministry in the preceding July on the rejection of Gladstone's home rule proposals by the House of Commons. He was at once appointed governor of Tasmania, and was succeeded as under-secretary by Major-general Sir Redvers Buller. In 1887, he presided over the meeting of the Australian federal council held at Hobart. He was very much in favour of the advancement of the Australian colonies, and encouraged industrial development, and road and railway works to be undertaken during his time in office. He was also strongly in favour of Australian federalism, and presided over the Federal Council of Australasia held in Hobart in 1887, 1888, and 1889. In 1887 he hosted an extravagant gala balls to mark Queen Victoria's golden jubilee in 1887, and was the president of the Royal Society of Tasmania. He helped to found the University of Tasmania, and promoted the establishment of schools, technical colleges and museums in Tasmania. Hamilton remained governor of Tasmania until 1893 ; on his return he was appointed royal commissioner to inquire into the working of the constitution of Dominica. In 1894, on Mr. Morley's nomination, he was placed on the commission appointed to inquire into the financial relations between England and Ireland, and in November of the same year he was made chairman of the board of customs. He died at 31 Redcliffe Square, South Kensington, on 22 April 1895, and was buried at Richmond, Surrey, on 26 April 1895.
On 18 August 1863 he married Caroline Jane Ball, and they had three sons and daughter. Their second son Robert William Hamilton who became Liberal MP for Orkney & Shetland. Caroline died in 1875. Their daughter Anne married Theyre à Beckett Weigall, a prominent Australian judge, and was the mother of the author Joan Lindsay. On 4 July 1877, he married Teresa Felicia, with whom he had a further two sons and one daughter.