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

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar

How to preserve numeric column types when concatenating tables with empty columns

Hello,

 

I have two tables ((imported from csv files initially) that I want to concatenate, each containing only one column, “Column 1” (see screenshot below). In the first table, there is no data; it is empty and of the Nominal character type (defaut, when exporting the csv).

In the second table, there is numerical data.

When I concatenate the two tables, the final format is nominal character even though there is numerical data.

Is there any option to have this detected automatically as numeric?

Additional information:
- It is automated, I have this problem on many columns.
- I do not know in advance which columns are numeric.
- I do not know in advance which tables have no data.

SophieCuvillier_0-1764257897084.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to preserve numeric column types when concatenating tables with empty columns

You can check if columns are numeric before concatenation and update final result accordingly. Or you could go over character columns after you are done concatenating and change them. I haven't tried this exact method myself (<< fail on conversion), but I think it should work fine

Names Default To Here(1);
dt = New Table("My Table",
	New Column("col1", Character, "Nominal", Set Values({"123", "456", "abc", "789", "", "def"})),
	New Column("col2", Character, "Nominal",Set Values({"123", "456", "789", "", "", ""}))
);

For Each({colname}, dt << Get Column Names("Character", "String"),
	r = Column(dt, colname) << Set Data Type("Numeric", <<Fail On Conversion Error, <<Return Failed Rows);

	If(N Items(r) == 0,
		Column(dt, colname) << Set Modeling Type("Continuous");
	);
);
-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: How to preserve numeric column types when concatenating tables with empty columns

You can check if columns are numeric before concatenation and update final result accordingly. Or you could go over character columns after you are done concatenating and change them. I haven't tried this exact method myself (<< fail on conversion), but I think it should work fine

Names Default To Here(1);
dt = New Table("My Table",
	New Column("col1", Character, "Nominal", Set Values({"123", "456", "abc", "789", "", "def"})),
	New Column("col2", Character, "Nominal",Set Values({"123", "456", "789", "", "", ""}))
);

For Each({colname}, dt << Get Column Names("Character", "String"),
	r = Column(dt, colname) << Set Data Type("Numeric", <<Fail On Conversion Error, <<Return Failed Rows);

	If(N Items(r) == 0,
		Column(dt, colname) << Set Modeling Type("Continuous");
	);
);
-Jarmo

Re: How to preserve numeric column types when concatenating tables with empty columns

Hello, thank you I didn't now about these functions it solved my issue ! 

Recommended Articles