MS Excel is great for sorting out stimuli so that it’s all nice and neat and in one place, like when I’ve organised my millions of EEG trigger codes:
…but some programmes (I’m looking at you here, Presentation) require individual .txt files of each column:
It’s easy enough to just copy the columns, paste them into Notepad, and save as .txt files if you don’t have too many, but to do that every time you make changes is really frustrating.
It’s easy enough to get Matlab to sort this out for you as well, but I’m kind of Matlab-phobic and prefer to use R for everything that needs scripting.
So, here’s a quick and dirty little snippet of code that goes through a spreadsheet and saves the contents of every individual column as a separate .txt file with the title of whatever is in the first row. All you have to do first is save your Excel sheet as a .csv file.
It’s messy code, but it does the job just fine and saves lots of time and frustration.
It’d be even easier with using xlsx::read.xlsx2(), then you could import the Excel file as-is.
LikeLike
Very true! I’ve kept this to only using the base packages, but that does work better.
LikeLike