- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Replace missing values with 0
Hello,
I'm trying to replace all missing values in a data table with 0. The below script doesn't work. I use JMP 13. Is there any other way to do this?
dt = Current Data Table();
nc = dt << get column names( Numeric );
For( i = 1, i <= N Items( nc ), i++,
nc[i][dt << get rows where( Is Missing( nc[i][] ) )] = 0
);
Thanks!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Replace missing values with 0
Here is the correct syntax for what you are trying to do
dt = Current Data Table();
nc = dt << get column names( Numeric );
For( i = 1, i <= N Items( nc ), i++,
Column( nc[i] )[dt << get rows where( Is Missing( As Column( nc[i] ) ) )] = 0
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Replace missing values with 0
Here is the correct syntax for what you are trying to do
dt = Current Data Table();
nc = dt << get column names( Numeric );
For( i = 1, i <= N Items( nc ), i++,
Column( nc[i] )[dt << get rows where( Is Missing( As Column( nc[i] ) ) )] = 0
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Replace missing values with 0
Hi Jim,
I tried the above, but getting the folliowing error.
could not find column in access or evaluation of 'Column' , Column/*###*/(nc[i])
Any idea what's going on? I use JMP 13, I'm not sure if the syntax isn't working for this version.
Thanks,
N
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Replace missing values with 0
Hi @nshivan,
I ran Jim's code in versions 13 and 14 and got no errors. Maybe restart JMP and run it again?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Replace missing values with 0
Hi Cameron,
I restarted JMP and the script works fine on the specific data table. The missing values get replaced with 0s. But when I integrate to the rest of my script, it gives me the below error:
could not find column in access or evaluation of 'Column' , Column/*###*/(nc[i])
Prior to this piece of script, I have an original data table which I subset based on selected columns, stack the data, summarize anf then tabulate into the final data table. I'm trying to replace missing values in the final data table with 0s.
I'm fairly new to JMP scripts, not sure why the integration is giving problems. Any idea why this is happening?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Replace missing values with 0
Something like this is hard to diagnose from a description. You'd probably have to post your script (or at least enough of it to replicate the problem) for us to help with it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Replace missing values with 0
try being a little more specific in your script.
give the data table that has the specific column in it a handle. Like dt=table(); or something like that.
then refer to the column in the table, dt::nameOFCol
It is likely that your script is trying to modify a column that doesn't exist in the table that is current when this step runs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Replace missing values with 0
I use this script constantly. Can't thank you enough for providing it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Replace missing values with 0
in Can I replace missing values in Numeric column with "N/A" string?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Replace missing values with 0
>> Can I replace missing values in Numeric column with "N/A" string?
Use value labels to do that. Right click on column header, go to column properties, select Value Labels. Then put a period in the value and N/A in the label field as shown below. Then click add, and then ok.
To script it, follow the log recorder of above steps...
Data Table( "DT name" ):Column 904 << Value Labels( {"." = "N/A"} ) << Use Value Labels( 1 );