cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Image to Table JMP extension imports single or batch images as data tables. Useful to extract curves from pictures or convert image data to curve data to use in analyses like Functional Data Explorer. Download and install the extension.

Discussions

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

Copy selection and paste into new columns

Hello, I have a set of columns with data for multiple products by rows. I need to split up this data by creating new identical columns with product name suffix and copy over only the matching product data from previous columns. I just need help to copy over appropriate data. I was trying to do this with selections and copy paste, but I am not sure how to. Region of interest is starting from dt << Select Where onwards.

Names Default To Here( 1 );
dt = Current Data Table();
colNames = dt << Get Column Names(String);
//Select set of columns to split
for (i = nitems(colNames), i > 0, i--,
     if (!contains(colNames[i], "SPC"),
           remove from(colNames, i);
     );
);

//Add new columns with product name suffix and copy/paste properties
Summarize(unique_values=by(:Products));
colNames2=colNames;
for (k = nitems(unique_values), k > 0, k--,
	for (i = nitems(colNames), i > 0, i--,
		colNames2[i] = colNames[i] || " " || unique_values[k];
		dt << New Column( colNames2[i] );
	); 
	for( j = 1, j <= nitems(colNames), j++,
		colProps = Column( dt, colNames[j] ) << Get Column Properties;
		Column( dt, colNames2[j] ) << Add Column Properties( colProps );
	);
	dt << Select Where( :Products == unique_values[k] );
		dt << selectColumns(colNames);
		dt << Copy;
		dt << selectColumns(colNames2);
		dt << Paste;
);

 

1 REPLY 1

Re: Copy selection and paste into new columns

Hi, If you want to copy and paste value based on row selection, you can write code like the following.

I hope it helps.

dt << Select Where( :Products == unique_values[k] );
r = dt << Get Selected Rows();
val = As Column( colNames[i] )[r];
For( h = 1, h <= N Row( val ), h++,
	As Column( colNames2[i] )[r[h]] = val[h]
);

Recommended Articles