Post Reply 
moving data from Spreadsheet into 2-Var based on a category
01-21-2015, 10:22 PM (This post was last modified: 01-21-2015 10:24 PM by Snorre.)
Post: #2
RE: moving data from Spreadsheet into 2-Var based on a category
Hello mbeddo,

Here's a simple program that is not very efficient/elegant but more a concept. It allows arbitrary count of rows and is easy to extend for new types (e.g. "C" for cats).
Code:
get_x_where_y_equals_z(x,y,z)
BEGIN
  LOCAL result:={},k;
  FOR k:=1 TO MIN(SIZE(x),SIZE(y)) DO
    IF y(k)=z THEN
      result:=CONCAT(result,x(k));
    END; 
  END;
  result;
END;

EXPORT DoStat()
BEGIN
  STARTAPP("Statistics 2Var");

  // Copy spreadsheet data to statistics app.
  C1:=get_x_where_y_equals_z(Spreadsheet.A:A,Spreadsheet.C:C,"M");
  C2:=get_x_where_y_equals_z(Spreadsheet.B:B,Spreadsheet.C:C,"M");
  C3:=get_x_where_y_equals_z(Spreadsheet.A:A,Spreadsheet.C:C,"F");
  C4:=get_x_where_y_equals_z(Spreadsheet.B:B,Spreadsheet.C:C,"F");

  // Define sets (S1=males, S2=females)
  SetIndep(S1,C1); SetDepend(S1,C2); CHECK(1);
  SetIndep(S2,C3); SetDepend(S2,C4); CHECK(2);

  // Show plot.
  STARTVIEW(9);
END;
Beware: your current app must be "Statistics 2Var" when entering/compiling. Otherwise you've to introduce a lot of "Statistics_2Var."-prefices into the code.
When running "DoStat", current app doesn't matter since it will always changed.

Greetings
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: moving data from Spreadsheet into 2-Var based on a category - Snorre - 01-21-2015 10:22 PM



User(s) browsing this thread: 1 Guest(s)