Reordering Variables
Jump to navigation
Jump to search
This code moves the selected questions to the bottom of the file and then reorders them so that Q2 appears before Q1. It creates an array of the selected variables and then loops through the variables by name and adds them to a new array in the specified order. You can change which variables to move by entering the appropriate variable name in the 'selected_vars' line below.
var data_file = project.dataFiles[0];
var selected_vars = ["Q2","Q1"];
var moved_vars = [];
for (var i = 0; i < selected_vars.length; i++) {
var curr_var = data_file.getVariableByName(selected_vars[i]);
var variables = data_file.variables;
data_file.moveAfter([curr_var],variables[variables.length-1]);
moved_vars.push(curr_var);
}
See also
- QScript for an explanation of how to run this code.
- QScript Examples Library for other examples.
- QScript Reference for technical information.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.
- JavaScript Variables for detail on how to create new variables in the Variables and Questions tab using JavaScript.