According to the Thomas Cook Rail Map of Europe, there are no rail services crossing the border between Estonia and Latvia. The Latvian rail system goes north as far as Lugazi which is close to Valga on the other side of the border.
Riga to Vilnius is simpler, with mainline services available via Daugavpils.
I've scanned the map to make things clearer to you. (If your browser resizes images to fit the window, click on the map to view it full size). If you need a wider area scanned, just post again to let me know:
http://i42.tinypic.com/1y8l90.jpg
Latvian Railways (with links to timetables, including international services, on the left):
http://www.ldz.lv/?object_id=861
Lithuanian Railways. (Use 'Route Search', under 'Quick Links', for timetables):
http://www.litrail.lt/wps/portal
Estonian Railways. (Timetable not available in English):
http://www.edel.ee/?CatID=6
Integrated rail timetable for the whole of Europe. (The timetable search, at the top left of the page, can cope with travel anywhere in Europe. e.g. Scunthorpe to Moscow, if you like!):
http://www.bahn.co.uk/db_uk/view/index.shtml
Further information. (Use the country links down the left):
http://www.seat61.com/
Chris