Hi again,
I have an experiment where I need to log leading zeros
The code looks like this in builder:
if condition > 0 & condition < 7:
target = str(pos1_letter) + str(pos2_letter) + str(pos3_letter) + str(pos4_letter) + str(pos5_letter) +'00000'
elif condition > 6 & condition < 13:
target = str('00000') + str(pos1_letter) + str(pos2_letter) + str(pos3_letter) + str(pos4_letter) + str(pos5_letter)
distractor = str("0000000000")
thisExp.addData('target',target)
thisExp.addData('distractor',distractor)
and this in JS:
if (((condition > (0 & condition)) && ((0 & condition) < 7))) {
target = (((((pos1_letter.toString() + pos2_letter.toString()) + pos3_letter.toString()) + pos4_letter.toString()) + pos5_letter.toString()) + "00000");
} else {
if (((condition > (6 & condition)) && ((6 & condition) < 13))) {
target = ((((("00000".toString() + pos1_letter.toString()) + pos2_letter.toString()) + pos3_letter.toString()) + pos4_letter.toString()) + pos5_letter.toString());
}
}
distractor = "0000000000".toString();
psychoJS.experiment.addData("target", target);
psychoJS.experiment.addData("distractor", distractor);
However, the .csv logfile (both on- and offline) refuses to store these leading zeros (or multiple zeros in the case of the distractor variable), despite my attempts at storing this as text and not as number.
Does anyone know a way around this?
Best wishes,
Bianca
Why do you need to “log” the leading zeros? The data file doesn’t have to show exactly what the participant saw.
Options are:
-
You could let the target and distractor be saved as numbers and know (in your analysis) that there were leading zeros
-
You could use ‘O’ instead of ‘0’ in your data file (whether or not you use it for your participants).
-
You could prepend a letter or punctuation to the string, e.g. `0000000000
-
You could divide the number by 10000000000 so you get a decimal, e.g. 0.0000012345 though this would still have 0000000000 as 0.
To analyse the data efficiently, I need the leading zeros unfortunately. I need the data to be in tab-delimited .txt format like this:
Basically, it’s a TVA study and I will analyse the data with LibTVA. Instead of letters, I am presenting numbers as I am assessing young children who are typically better at reporting numbers than letters. I would like to avoid needing to do extensive editing of data afterwards to get it into the correct format, which would be the case for your suggested solutions.
Is there any way at all to get PsychoPy/Pavlovia to export a tab-delimited text file like this? Am happy to do this via code if necessary.
Have you checked the csv files you are getting in a text editor (as opposed a spreadsheet editor)?
OK, we seem to be getting somewhere, as it at least shows the 10 zeros for the distractor condition.
Two problems remaining:
- Despite setting data file delimiter to “tab” in PsychoPy, Pavlovia insists on giving me comma-separated files
- Somehow my code does not seem to do leading zeros when condition >6 and <13, but that most likely reflects an error in my code…
Is there a way to get Pavlovia to generate tab-delimited files as opposed to comma-separated files?
I can save the .csv file Pavlovia generated as tab-separated .txt, but then I lose my lovely zeros again:
What software are you using to open the CSV file, and save the .txt file?
The only way that it will get rid of the leading zeroes is if it’s in some software that doesn’t work in plain text and tries to convert things to numbers, like Excel. I think you just need to open the csv file in a plain-text editor like BBEdit (on Mac) or Notepad++ (on Windows) and save it as a txt, and then only open it in software that works in plain text.
1 Like
@bianhaan
You can use a text editor such as notepad++ to replace a , with a tab in several files at once. A good statistics software will read files with any kind of column separator (tsv, csv, semicolon, space, fixed format) without any problem. Stay away from Excel.
Best wishes Jens
OK. Had been using “normal” notepad, but found notepad++ online. We don’t have admin rights on our work computer, but will see if I can convince IT. Thank you.