cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • 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
JazzlikeMag
Level I

JSL question: Update missing column entries from another column

Hi all,

 

I need to update missing column entries in a data table, with entries from another older column. Using JSL code, and on JMP 14.

Here is the code I am trying to work, but it keeps on throwing error "attempting to assign to an object... L-value access.."

Any help will be appreciated..

 

dt=current data table();
Newcols={ "anew", "bnew", "cnew"};
oldcols={ "a", "b", "c"};
		
		
//---Update entries from old cols if new column entry is missing
For( k = 1 , k <= Length( oldcols ), k++,
				
		
		For Each Row(
			temp = column(dt, Newcols[k]); 
			oldc = column(dt, oldcols[k]);
			column (dt,Newcols[k]) = If( Is Missing( as column(dt,Newcols[k]) ) , oldc , temp) ;
			);
	);

 

 

2 REPLIES 2
jthi
Super User

Re: JSL question: Update missing column entries from another column

One option would be to use << Set Each Value()

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(4),
	New Column("a", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 3, 4])),
	New Column("b", Numeric, "Continuous", Format("Best", 12), Set Values([5, 6, 7, 8])),
	New Column("a2", Numeric, "Continuous", Format("Best", 12), Set Values([11, ., 33, 44])),
	New Column("b2", Numeric, "Continuous", Format("Best", 12), Set Values([., ., 77, .]))
);

wait(2); // demo purposes

new_cols = {"a2", "b2"};
old_cols = {"a", "b"};

For(i = 1, i <= N Items(old_cols), i++,
	Column(dt, new_cols[i]) << Set Each Value(
		If(Is Missing(AsColumn(Column(dt, new_cols[i]))),
			AsColumn(Column(dt, old_cols[i]))
		,
			AsColumn(Column(dt, new_cols[i]))
		)
	)
);

I think you have to provide Column with [] or [Row()] if you want to add values like you suggested


For(k = 1, k <= Length(old_cols), k++,
	For Each Row(
		new_col_val = Column(dt, new_cols[k])[];
		old_col_val = Column(dt, old_cols[k])[];
		Column(dt, new_cols[k])[] = If(Is Missing(new_col_val), old_col_val, new_col_val)
	)
);

or use As Column

For(k = 1, k <= Length(old_cols), k++,
	For Each Row(
		new_col_val = AsColumn(dt, new_cols[k]);
		old_col_val = AsColumn(dt, old_cols[k]);
		AsColumn(dt, new_cols[k])[] = If(Is Missing(new_col_val), old_col_val, new_col_val)
	)
);
-Jarmo
JazzlikeMag
Level I

Re: JSL question: Update missing column entries from another column

Many Thanks, this worked !

Recommended Articles