How to set variable names using Readtable with hierarchical categories (Excel file with merged cells / multiple header rows)
I have an Excel file with a series of header rows containing a hierarchy of descriptors. I would like to use this existing hierarchy to access the data. In the image below, I have data for various engineering majors (electical, mechincal, …) that are split by year of study (freshman, sophomore, …), then by gender, and finally my domestic versus international. This heirachy repeats for each major and there are many rows of data corresponding to academic years (not pictured in the table below) going back a long way. Is there a way to use readtable or a similar function to load that data in such a way that I can retrieve a specific number. For example, can I import the data in such a way that I could retrieve it with something like the following pseudo-code
table = readtable(‘filename’, <other options>)
table(major=electrical, gender=female, <additional options>)
% or even
table(row1=’electrical’, row2=’female’, <additional options>)
Alternatively, can I manipulate the way column names are created? WIthout any tweaking I get names like
‘dometic’, ‘domestic_1’, ‘domestic_2’, …
What I would prefer is to get column names such as
‘electrical-freshman-male-domestic’
‘electrical-freshman-female-domestic’
‘electrical-freshman-unspecified-domestic’
‘electrical-sophomore-male-domestic’
…
and likewise for other combinations so that I drill down to the appropriate column of data.I have an Excel file with a series of header rows containing a hierarchy of descriptors. I would like to use this existing hierarchy to access the data. In the image below, I have data for various engineering majors (electical, mechincal, …) that are split by year of study (freshman, sophomore, …), then by gender, and finally my domestic versus international. This heirachy repeats for each major and there are many rows of data corresponding to academic years (not pictured in the table below) going back a long way. Is there a way to use readtable or a similar function to load that data in such a way that I can retrieve a specific number. For example, can I import the data in such a way that I could retrieve it with something like the following pseudo-code
table = readtable(‘filename’, <other options>)
table(major=electrical, gender=female, <additional options>)
% or even
table(row1=’electrical’, row2=’female’, <additional options>)
Alternatively, can I manipulate the way column names are created? WIthout any tweaking I get names like
‘dometic’, ‘domestic_1’, ‘domestic_2’, …
What I would prefer is to get column names such as
‘electrical-freshman-male-domestic’
‘electrical-freshman-female-domestic’
‘electrical-freshman-unspecified-domestic’
‘electrical-sophomore-male-domestic’
…
and likewise for other combinations so that I drill down to the appropriate column of data. I have an Excel file with a series of header rows containing a hierarchy of descriptors. I would like to use this existing hierarchy to access the data. In the image below, I have data for various engineering majors (electical, mechincal, …) that are split by year of study (freshman, sophomore, …), then by gender, and finally my domestic versus international. This heirachy repeats for each major and there are many rows of data corresponding to academic years (not pictured in the table below) going back a long way. Is there a way to use readtable or a similar function to load that data in such a way that I can retrieve a specific number. For example, can I import the data in such a way that I could retrieve it with something like the following pseudo-code
table = readtable(‘filename’, <other options>)
table(major=electrical, gender=female, <additional options>)
% or even
table(row1=’electrical’, row2=’female’, <additional options>)
Alternatively, can I manipulate the way column names are created? WIthout any tweaking I get names like
‘dometic’, ‘domestic_1’, ‘domestic_2’, …
What I would prefer is to get column names such as
‘electrical-freshman-male-domestic’
‘electrical-freshman-female-domestic’
‘electrical-freshman-unspecified-domestic’
‘electrical-sophomore-male-domestic’
…
and likewise for other combinations so that I drill down to the appropriate column of data. readtable, readcell, table MATLAB Answers — New Questions