Announcing the new Datavyu v1.4.0 with enhanced features, bug fixes, and a new video player for Windows!

We are in the process of migrating away from this forum—feel free to browse existing help topics. For new support inquiries, please reach out to us via email at

Hello, I am trying to create a custom column where the value is dependent on multiple values from other columns. For example, I have a column called trials where there are codes for right and left object. I have another column called looking, which has direction code. I would like to copy the looking column (onsets and offsets) and change the direction code based off the right and left object. Essentially, I would like to make an if statement to change the looking codes. Thus far I have called all of the necessary columns and created a new columns with a object look code in a script. But am not sure how to copy the column or make the if statement.

I also wanted to create a new column which copies the codes in another column but breaks the cell into fourths. For example the first cell is 4 seconds long and I would like to create a new column with 1 second cells based on the onset and offset of the four second cell with the same codes.

Any help is much appreciated.

Thank you, Laura

asked 26 Mar '16, 09:21

laura-colosimo's gravatar image

accept rate: 0%

Hi Laura,

Let's start with the first task. I am assuming that cells inside the looking column are temporally nested inside the trial cells (looking onset >= trial onset and looking offset <= trial offset...etc).

In this case, here is a sample template for a script that loops over the trial cells and sets the necessary direction code.

trial_column = getVariable('trial')
looking_column = getVariable('looking')
new_column = createVariable('new_column', 'direction')

trial_column.cells.each do |tcell|
  # Loop over cells in the looking column cells which are nested (contained) insided the trial cell{ |x| tcell.contains(x) }.each do |lcell|
    # Make a new cell for this looking cell and change onset and offset
    ncell = new_column.make_new_cell
    ncell.onset = lcell.onset
    ncell.offset = lcell.offset
    # If statements here to change new cell's direction code based on tcell and lcell codes
    # For example:
    if( tcell.dir == 'l' && lcell.direction == 'u' )
      ncell.direction = 'blah'
    elsif( ... )


You'll of course have to change the code and column names to match your spreadsheet and replace the ellipses with additional code.

For the second task, the idea is similar but instead of creating one new cell per original cell, you'll have to create four new cells. Here's a concise example with some of the setting up code omitted:

trial_column.cells.each do |tcell|
  d = tcell.duration/4 # duration of new cells is one-fourth of trial cell
  1.upto(4) do |i|
    ncell = new_column.make_new_cell
    ncell.onset = tcell.onset + (i-1) * duration
    ncell.offset = tcell.onset + i * duration

You will need to adjust the formula to suit your preference for onset offset (e.g. adding 1 millisecond to the onset for cells 2-4).

I hope this is sufficient. If you have any follow up questions, feel free to ask.

permanent link

answered 29 Mar '16, 16:37

Shohan%20Hasan's gravatar image

Shohan Hasan ♦♦
accept rate: 14%

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: 26 Mar '16, 09:21

question was seen: 2,273 times

last updated: 29 Mar '16, 16:37

powered by OSQA