BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar
Highlighted
CharlesIII

Occasional Contributor

Joined:

Jun 20, 2018

Creating a subset of data based on a list of columns

Hello,

I have a large data file with many columns of data. I would like to create an automated way to subset the raw data based on a list of columns. 

 

If this table is my raw data 

12345678910
##########
##########

and my list of columns that I would like to subset may be [1,4,6,9]

I want to generate a new table that looks like this

1469
####
####

 

The reason I can't just hardcode what columns to take is the list will is updated every so often so I would like a more hands-free way of dealing with this. 

 

If I need to provide more information let me know. 

 

Thanks! 

1 ACCEPTED SOLUTION

Accepted Solutions
cwillden

Super User

Joined:

May 1, 2017

Solution

Re: Creating a subset of data based on a list of columns

This is probably really easy, but I'm confused about your list.  You say you can't hardcode in which columns to use because it will change, but doesn't someone need to ultimately enumerate the columns to use when the list gets updated?  Otherwise, where does that list come from? If you have a variable right at the top of the script that enumerates all the columns to use, is that sufficiently easy to maintain?  If so, here's a simple script that does that:

//list of columns
subset_cols = {:Name("1"), :Name("4"), :Name("6"), :Name("9")};

dt = Current Data Table();
dt << Subset(	All rows, columns( subset_cols ) )
-- Cameron Willden
1 REPLY 1
cwillden

Super User

Joined:

May 1, 2017

Solution

Re: Creating a subset of data based on a list of columns

This is probably really easy, but I'm confused about your list.  You say you can't hardcode in which columns to use because it will change, but doesn't someone need to ultimately enumerate the columns to use when the list gets updated?  Otherwise, where does that list come from? If you have a variable right at the top of the script that enumerates all the columns to use, is that sufficiently easy to maintain?  If so, here's a simple script that does that:

//list of columns
subset_cols = {:Name("1"), :Name("4"), :Name("6"), :Name("9")};

dt = Current Data Table();
dt << Subset(	All rows, columns( subset_cols ) )
-- Cameron Willden