Merging CSV files into table
I am trying to find a way to read each csv file with read table and merge into a big table without “heavy” coding. I am having problems merging the tables due to a somewhat non-uniform data structure and wonder if the process of making the table uniform can be done in Matlab (instead of copy pasting in excel).
Questions:
How to I check if variable exist in csv file?
How do I concatenate specific variables to existing table?
Problem: The original data are in csv files and organized as follows:
There is one csv file for each year
The data structure is not the same in each csv file. Eg file2001.csv may have variables “height” only; file 2005.csv may have variable “height” and “colour” and 20015.csv may have “height”, “size” and “colour”.
Generic Code:
Table2001=readtable(‘file2001.csv); % contains subset of variables
Table2005=readtable(‘file205.csv); % contains subset of variablesTable2015=readtable(‘file2015.csv); % contains all variables)
Create big table
T = Table2015; % starting table as it contains all variables
Check if “height” is a variable in Table2001; if yes, concatenate column below T.height if no, add column of NAN below T.heightcontinue process for all variables and files
Best Answer