cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-495942%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3Espostare%20le%20colonne%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-495942%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ECiao%20a%20tutti%2C%20vorrei%20spostare%20tutte%20le%20colonne%20a%20destra%20di%20una%20colonna%20se%20le%20righe%20dove%20la%20lunghezza%20%C3%A8%20maggiore%20di%203%20nella%20prima%20colonna%20e%20vorrei%20sapere%20se%20questo%20%C3%A8%20possibile%3F%20per%20il%20momento%20parto%20da%20questo%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%26lt%3B%26lt%3B%20delete%20row(%201%20)%3B%0A%0Arows_to_delete%20%3D%20dt%20%26lt%3B%26lt%3B%20Get%20Rows%20Where(Length(%20%3AProdn%20Supervisor%20)%26gt%3B3)%3B%0AIf(N%20Items(rows_to_delete)%2C%0A%20dt%20%26lt%3B%26lt%3B%20Delete%20Rows(rows_to_delete)%3B%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22NetflixCrow956_0-1653996745107.png%22%20style%3D%22width%3A%20883px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22NetflixCrow956_0-1653996745107.png%22%20style%3D%22width%3A%20883px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22NetflixCrow956_0-1653996745107.png%22%20style%3D%22width%3A%20883px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22NetflixCrow956_0-1653996745107.png%22%20style%3D%22width%3A%20883px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22NetflixCrow956_0-1653996745107.png%22%20style%3D%22width%3A%20883px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22NetflixCrow956_0-1653996745107.png%22%20style%3D%22width%3A%20883px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22NetflixCrow956_0-1653996745107.png%22%20style%3D%22width%3A%20883px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22NetflixCrow956_0-1653996745107.png%22%20style%3D%22width%3A%20883px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22NetflixCrow956_0-1653996745107.png%22%20style%3D%22width%3A%20883px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22NetflixCrow956_0-1653996745107.png%22%20style%3D%22width%3A%20883px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F42795i77661B006BEAA0CC%2Fimage-dimensions%2F883x183%3Fv%3Dv2%22%20width%3D%22883%22%20height%3D%22183%22%20role%3D%22button%22%20title%3D%22NetflixCrow956_0-1653996745107.png%22%20alt%3D%22NetflixCrow956_0-1653996745107.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-495942%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3ESceneggiatura%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-495994%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20spostare%20le%20colonne%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-495994%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EPer%20il%20momento%20elimino%20queste%20colonne%20ma%20vorrei%20spostarle%20a%20destra%20come%20spiegato%20sopra%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
NetflixCrow956
Level III

move columns

Hello everyone, I would like to shift all columns to the right by one column if the lines where the length is greater than 3 in the first column and I would like to know if this is possible? for the moment, I starting by this : 

 

 

dt << delete row( 1 );

rows_to_delete = dt << Get Rows Where(Length( :Prodn Supervisor )>3);
If(N Items(rows_to_delete),
	dt << Delete Rows(rows_to_delete);
);

 

NetflixCrow956_0-1653996745107.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: move columns

Depending on your data something like this might work, it uses Data table subscripting

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(4),
	New Column("A", Character, "Nominal", Set Values({"AAAA", "AAAA", "BBB", "BBB"})),
	New Column("B", Character, "Nominal", Set Values({"123", "456", "AAAA", "AAAA"}), Set Display Width(45)),
	New Column("C", Numeric, "Continuous", Format("Best", 12), Set Values([., ., 789, 0]))
);

rows_to_shift =  dt << Get Rows Where(Length(AsColumn(1)) > 3);
col_count = N Cols(dt);

// set all columns to character to make this easier
For Each({col_name}, dt << Get Column Names("String"),
	Column(dt, col_name) << Set Data Type("Character");
);
wait(1);

// Datatable subscripting
dt[rows_to_shift, 2::col_count] = dt[rows_to_shift, 1::col_count - 1];
dt[rows_to_shift, 1] = ""; // set first column values as missing
-Jarmo

View solution in original post

3 REPLIES 3
NetflixCrow956
Level III

Re: move columns

For the moment I delete these columns but I would like to move them to the right as explained above

jthi
Super User

Re: move columns

Depending on your data something like this might work, it uses Data table subscripting

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(4),
	New Column("A", Character, "Nominal", Set Values({"AAAA", "AAAA", "BBB", "BBB"})),
	New Column("B", Character, "Nominal", Set Values({"123", "456", "AAAA", "AAAA"}), Set Display Width(45)),
	New Column("C", Numeric, "Continuous", Format("Best", 12), Set Values([., ., 789, 0]))
);

rows_to_shift =  dt << Get Rows Where(Length(AsColumn(1)) > 3);
col_count = N Cols(dt);

// set all columns to character to make this easier
For Each({col_name}, dt << Get Column Names("String"),
	Column(dt, col_name) << Set Data Type("Character");
);
wait(1);

// Datatable subscripting
dt[rows_to_shift, 2::col_count] = dt[rows_to_shift, 1::col_count - 1];
dt[rows_to_shift, 1] = ""; // set first column values as missing
-Jarmo
txnelson
Super User

Re: move columns

Something like this should work

Names Default To Here( 1 );
dt = Current Data Table();

dt << delete row( 1 );

theRows = dt << Get Rows Where( Length( :Prodn Supervisor ) > 3 );

If( N Items( theRows ) > 0,
	For( theCol = 1, theCol < N Col( dt ), theCol++,
		For( myRow = 1, myRow <= N Items( theRows ), myRow++,
			Column( theCol )[theRows[myRow]] = Column( theCol + 1 )[theRows[myRow]]
		)
	)
);
Jim

Recommended Articles