0

I am performing a query in an database using linq-to-sql to retrieve a DataTable in C#. Now, in this DataTable, I want to find how many categories I have in a specific columns. Let's say the column's name is "Variable" and the values for the different rows would be for example:

["a", "a", "a", "b", "b", "c", "c", "c", "c"]

I just want to know what categories this column contain. So in this case that would be the categories "a", "b", and "c".

This would be done easily in R using levels(DataTable$Variable).

But how to do that in C# ?

Thanks

bricx
  • 563
  • 3
  • 16
  • Can you not just use some variation of `SELECT DISTINCT Variable FROM DataTable`? – Mako212 Jan 31 '19 at 00:02
  • Also see [this answer](https://stackoverflow.com/a/9685/4421870) – Mako212 Jan 31 '19 at 00:06
  • Perfect, the second option was all I needed ! Thanks ! – bricx Jan 31 '19 at 00:20
  • Yes, but I never thought about searching for removing duplicates... probably because I am coming from an R background... so it might be helpful to others to leave the question here ? – bricx Jan 31 '19 at 00:23
  • It will stay as-is unless enough people corroborate the duplicate flag to mark it as a duplicate. If that happens, the question remains, but there will be a link at the top of the question to the question that has been answered. – Mako212 Jan 31 '19 at 00:25
  • Got it, yes I just marked it as duplicate. – bricx Jan 31 '19 at 00:27

0 Answers0