cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Neo
Neo
Level VI

Copy values from specific columns of an exiting data-table to another data-table while multiplying selected rows by a constant

I have been able to do the first part (copy) but I am struggling with the second (multiply) part. Any direction is appricated. My example script is below.

Names Default To Here( 1 );
bcdt = Open( "$SAMPLE_DATA\Big Class.jmp", invisible ); //load a data-table

myNewdt = New Table( "Parameters Table", //create a new data-table
	Add Rows(8),
	New Column( "Parameter" ),
	New Column( "H", Numeric),
	New Column( "W" ),
);

Column(myNewdt, "Parameter")[1] = "A";
Column(myNewdt, "Parameter")[2] = "B";
Column(myNewdt, "Parameter")[3] = "C";
Column(myNewdt, "Parameter")[4] = "D";
Column(myNewdt, "Parameter")[5] = "E";
Column(myNewdt, "Parameter")[6] = "F";
Column(myNewdt, "Parameter")[7] = "G";
Column(myNewdt, "Parameter")[8] ="I";

vals = Column(bcdt, "height")[4::11]; //get the values to be copied. Note data type becomes "character"
//show (vals);

For( i = 1, i <= N Items(Vals), i++,  //copy values 
	:H[i] =  vals[i] 
);

The above script copies the values in column "height" of data file bcdt to column "H" of another data file myNewdt. However, I want for e.g. the 9th and 10th row entries in column "height" of bcdt  to be multiplied by a constant number, say 0.0001 and pass it on to the same rows (9th & 10th) of column "H" of the other data file myNewdt. The other row values are to be copied unmodified. How to achieve this?

When it's too good to be true, it's neither
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Copy values from specific columns of an exiting data-table to another data-table while multiplying selected rows by a constant

Here is the way I would handle this

Names Default To Here( 1 );
bcdt = Open( "$SAMPLE_DATA\Big Class.jmp", invisible ); //load a data-table

myNewdt = New Table( "Parameters Table", //create a new data-table
	Add Rows(8),
	New Column( "Parameter" ),
	New Column( "H", Numeric),
	New Column( "W" ),
);

Column(myNewdt, "Parameter")[1] = "A";
Column(myNewdt, "Parameter")[2] = "B";
Column(myNewdt, "Parameter")[3] = "C";
Column(myNewdt, "Parameter")[4] = "D";
Column(myNewdt, "Parameter")[5] = "E";
Column(myNewdt, "Parameter")[6] = "F";
Column(myNewdt, "Parameter")[7] = "G";
Column(myNewdt, "Parameter")[8] ="I";


bcdt:height[9] = bcdt:height[9] * .0001;
bcdt:height[10] = bcdt:height[10] * .0001;
vals = Column(bcdt, "height")[4::11]; //get the values to be copied. Note data type becomes "character"

myNewdt:H << set values(vals);

// or

//vals = Column(bcdt, "height")[4::11]; //get the values to be copied. Note data type becomes "character"
//vals[6] = vals[6] * .0001;
//vals[7] = vals[7] * .0001;
//myNewdt:H << set values(vals);

// or

//vals = Column(bcdt, "height")[4::11]; //get the values to be copied. Note data type becomes "character"
//myNewdt:H << set values(vals);
//myNewdt:height[6] = myNewdt:height[6] * .0001;
//myNewdt:height[7] = myNewdt:height[7] * .0001;
Jim

View solution in original post

2 REPLIES 2
frank_wang
Level IV

Re: Copy values from specific columns of an exiting data-table to another data-table while multiplying selected rows by a constant

Hi Neo

My script as annex. Hope it can help you to sovle the issue.

 

心若止水
txnelson
Super User

Re: Copy values from specific columns of an exiting data-table to another data-table while multiplying selected rows by a constant

Here is the way I would handle this

Names Default To Here( 1 );
bcdt = Open( "$SAMPLE_DATA\Big Class.jmp", invisible ); //load a data-table

myNewdt = New Table( "Parameters Table", //create a new data-table
	Add Rows(8),
	New Column( "Parameter" ),
	New Column( "H", Numeric),
	New Column( "W" ),
);

Column(myNewdt, "Parameter")[1] = "A";
Column(myNewdt, "Parameter")[2] = "B";
Column(myNewdt, "Parameter")[3] = "C";
Column(myNewdt, "Parameter")[4] = "D";
Column(myNewdt, "Parameter")[5] = "E";
Column(myNewdt, "Parameter")[6] = "F";
Column(myNewdt, "Parameter")[7] = "G";
Column(myNewdt, "Parameter")[8] ="I";


bcdt:height[9] = bcdt:height[9] * .0001;
bcdt:height[10] = bcdt:height[10] * .0001;
vals = Column(bcdt, "height")[4::11]; //get the values to be copied. Note data type becomes "character"

myNewdt:H << set values(vals);

// or

//vals = Column(bcdt, "height")[4::11]; //get the values to be copied. Note data type becomes "character"
//vals[6] = vals[6] * .0001;
//vals[7] = vals[7] * .0001;
//myNewdt:H << set values(vals);

// or

//vals = Column(bcdt, "height")[4::11]; //get the values to be copied. Note data type becomes "character"
//myNewdt:H << set values(vals);
//myNewdt:height[6] = myNewdt:height[6] * .0001;
//myNewdt:height[7] = myNewdt:height[7] * .0001;
Jim

Recommended Articles