Thank you everyone for all your prompt replies.
Colin, regarding the 1841 census record with John and Mary Brown (and children Margaret, Alexander and James), I also think John's age has been mistranscibed and should be as it is in the 1851 census record, i.e. c1786. I haven't been able to find out further info for them after 1851. (There is a 1871 census record and subsequent 1877 death record for a Mary Brown nee Shaw, widow of John Brown, seaman in Troon but I wanted to confirm if she was Shaw by checking out daughter Margaret's later records).
Nanville, thank you for your info on the Anderson family. I do indeed see that Margaret was probably the second wife. I will check out the birth records for the children born after 1855, and the 1910 death record for Margaret herself, and should confirm Margaret's maiden name. It may well be Shaw or Niel, as suggested as Colin.
Nanville, you don't happened to know where Margaret lived in later years, do you? Did she stay in Ayr?
Thanks again.