I have a Character Col that all input value is in time, like hh:mm:ss (like 05:36:50), I would like to convert it to numeric, nominal type with a format of h:m.
The script I wrote for this request is listed below, but it does not work out as expected, can anyone give it a modify?
dt<<Current Data Table();
dt<< New Column("Time_Set",Numeric, Nominal, Format("h:m"));
dt<< Being data update;
For each row(:Time_Set=Num(":Time Added:"));
dt<< Move Selected Columns ({"Time_Set"},After("Time Added:"));
The trailing colon in your column name is what threw me. This code will work:
dt = Current Data Table();
dt << New Column("Time_Set",Numeric, Nominal, Format("h:m"));
for (i = 1, i <= nrows(dt), i++,
:time_set[i] = informat(:name("Time Added:")[i], "h:m:s");
);
dt = Current Data Table();
dt << New Column("Time_Set",Numeric, Nominal, Format("h:m"));
for (i = 1, i <= nrows(dt), i++,
:time_set[i] = informat(:Time Added[i], "h:m:s");
);
Hi PMroz,
I tried the script you wrote, but it did not work out. A Time_Set is created under numeric nominal type, but the entire column is blank.
Thanks,
Can you post a portion of your data? Perhaps your character time column is not quite in the right format, e.g. leading/trailing spaces etc.
Hi PMorz,
The uploaded file is the sample file. Thanks for your help!
please let me know if you cannot open it.
The trailing colon in your column name is what threw me. This code will work:
dt = Current Data Table();
dt << New Column("Time_Set",Numeric, Nominal, Format("h:m"));
for (i = 1, i <= nrows(dt), i++,
:time_set[i] = informat(:name("Time Added:")[i], "h:m:s");
);
Thanks, PMorz....
A quick note on the Informat() function – it doesn't require a second argument. If you leave it off, JMP will try all the formats it knows to interpret the first argument as a date/time value.
-Jeff