SD Data Logging with High Sampling Rate

I have an arduino Yun and I am trying to read voltage at a high sampling rate and write it to an sd card. Unfortunately I am relatively new to arduinos and optimizing the code for speed. I am seeing that if I use analogRead it will print to Serial at 1000 Hz, but when I try to write to the sd card after each sample, it varies between 2-4 Hz. My understanding is it takes time to open the file on the sd card and write to it and close it again and to get up to 1000 Hz.

How can I get a sampling rate of up to 1000 Hz and write to the sd card? I have read posts from others who have done it, but I can't compile their uploaded code and I don't understand the errors I am getting.

There was a post in the last couple of weeks from the author of the SD library which demonstrated performing analog reads on multiple inputs and writing the results to SD at better than 1KHz. I suggest you do a search for it, because it demonstrated that what you're asking for is definitely achievable, and gave you working code to achieve it.

Yup, here it is: http://forum.arduino.cc/index.php?topic=228549.0

Pete