Please use our GitHub Issues page for all new support inquiries. If you need to contact us directly, please e-mail [email protected]

How can I create a brand new column based on previously coded data? As in, I coded column A, but now I want to make a new column B with a cell for every time some event happened in column A.

asked 16 Jan '12, 16:08

Jesse's gravatar image

Jesse ♦
accept rate: 53%

edited 23 Jul '12, 09:38

Clinton's gravatar image


The answer is with a Ruby script!

For a simple example, lets say we had a column ColA that has some cells in it, and has an argument called <hand>, which is coded L or R, depending on which hand a person used to reach for something. Now we want a script to make a new column called ColB that has a cell with an argument <reachtype> for all of the left hand reaches only (i.e., when hand is L). We also have to set the onsets and offsets of the new cells to match the cells they were generated from.

#First get ColA from the database
colA = getVariable("ColA")

#Now we make a new variable called ColB with argument reachtype. 
#If we wanted more arguments, we could just add them after reachtype.
colB = createNewVariable("ColB", "reachtype")

#Now we want to loop thru all of the cells in colA, and add a cell to colB each
#time we find a cell matching our criteria: the hand argument is l
for acell in colA.cells
   #Check if the hand argument is l
   if acell.hand == "l"
      # Create a new cell in ColB
      bcell = colB.make_new_cell

# Now change the onset and offset of that cell to match the cell from ColA
      bcell.change_arg("onset", acell.onset)
      bcell.change_arg("offset", acell.offset)

setVariable("ColB", colB)

Remember that the lines that start with # are just comments, they are not executed.

permanent link

answered 26 Jan '12, 04:05

Jesse's gravatar image

Jesse ♦
accept rate: 53%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 16 Jan '12, 16:08

question was seen: 4,245 times

last updated: 23 Jul '12, 09:38

powered by OSQA