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
Mcc99
Level III

Script to change data type for all columns that contain a string in their header?

I'm trying to write a script to change all the columns with the word "Mean" in their header to numeric data type and continuous modeling type. 

I'm getting the error that "Send Expects Scriptible Object" regarding the last line "cols << data type("numeric")". How would I fix my code? Or is there an easier way to accomplish the same task? 

cols = dt << get column names( string );
For( i = N Items( cols ), i>=1, i--,
	If( Contains( cols[i], "Mean" ),
	 cols << data type("numeric");  
	)
);

I'm using JMP Pro 16. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Script to change data type for all columns that contain a string in their header?

You are sending the message to wrong variable. Something like

cols = dt << get column names(string);
For(i = N Items(cols), i >= 1, i--,
	If(Contains(cols[i], "Mean"),
		Column(dt, cols[i] << data type("numeric")
	)
);

should work. I would also rewrite the script a little (use For Each and << Set Data Type) as I think those are easier to read

cols = dt << get column names("String");

For Each({col}, cols,
	If(Contains(col, "Mean"),
		Column(dt, col) << Set Data Type("Numeric");
	);
);
-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Script to change data type for all columns that contain a string in their header?

You are sending the message to wrong variable. Something like

cols = dt << get column names(string);
For(i = N Items(cols), i >= 1, i--,
	If(Contains(cols[i], "Mean"),
		Column(dt, cols[i] << data type("numeric")
	)
);

should work. I would also rewrite the script a little (use For Each and << Set Data Type) as I think those are easier to read

cols = dt << get column names("String");

For Each({col}, cols,
	If(Contains(col, "Mean"),
		Column(dt, col) << Set Data Type("Numeric");
	);
);
-Jarmo
Mcc99
Level III

Re: Script to change data type for all columns that contain a string in their header?

Thanks! That second script works great. 

Recommended Articles