Error: Left and right key variables are not comparable because one is a non-cell

20 views (last 30 days)
Hi,
I have two tables which I want to join using the join() function. However, when I try to join them together like so:
load questionnaire_table.mat
load DFA_PCA_table.mat
load high_dfa_ID_table.mat
load PCA_table.mat
Full_high_data_set_table = join(questionnaire_table,DFA_PCA_table)
Full_high_data_set_table = 17×27 table
ID loc_internal_locus_of_control loc_powerful_others loc_chance empathy_perspective_taking empath_fantasy empathy_empathic_concern empathy_personal_distress itc_spatial_presence itc_engagement itc_ecological_validity itc_negative_effects_rows DFA_phase_1 DFA_phase_2 DFA_phase_3 DFA_phase_4 DFA_phase_5 PCA1_phase_1 PCA1_phase_2 PCA1_phase_3 PCA2_phase_4 PCA2_phase_5 PCA2_phase_1 PCA2_phase_2 PCA2_phase_3 comptable_high_pca_2_ID5 comptable_high_pca_2_ID6 __________________________ _____________________________ ___________________ __________ __________________________ ______________ ________________________ _________________________ ____________________ ______________ _______________________ _________________________ ___________ ___________ ___________ ___________ ___________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ________________________ ________________________ "61520b079436973e05f72d33" 31 23 26 18 12 14 16 3.3333 3.4615 2.4 1 1.6276 1.6811 1.6317 1.6948 1.607 60.351 92.232 77.059 61.229 63.239 4 1 4 3 3 "5f5503435d41a489068ff50b" 28 18 21 17 19 15 11 3.2222 3.2308 2.8 2 1.6466 1.6342 1.6335 1.6368 1.7084 59.128 50.854 51.244 66.032 51.386 4 4 4 3 4 "61728b3e4e680d6c607f514c" 10 33 24 8 18 14 22 4.1111 4.2308 3.8 1.1667 1.5956 1.7259 1.6352 1.7089 1.6748 52.065 67.773 93.596 50.603 91.444 4 2 1 3 1 "614ec4f7be36eb900905644c" 41 13 24 25 11 17 7 3.7778 3.9231 3.4 1.6667 1.4783 1.6334 1.6725 1.6926 1.6961 99.961 83.792 89.069 84.172 94.264 1 2 2 2 1 "6155c449ebffeae654abd854" 12 31 37 16 22 9 5 2.9444 3.0769 3.2 2.6667 1.6249 1.6795 1.63 1.659 1.642 44.8 76.618 84.346 83.478 58.59 4 2 2 2 3 "6134c80f7eab0971588b3d3a" 36 12 22 11 13 14 10 4.0556 4.3077 4.8 1.5 1.5811 1.6629 1.7217 1.7476 1.726 76.684 80.856 78.872 70.078 80.126 3 2 2 3 3 "5fb6ed2116919c000a99249e" 33 34 37 13 23 16 19 3.5556 3.6154 3.6 1 1.6919 1.7101 1.6341 1.6829 1.6828 64.623 62.614 44.905 81.629 68.942 3 3 4 2 2 "5dc4bc30569be3387eb6b52f" 15 17 32 10 18 17 25 3 3.7692 2.6 1.1667 1.5251 1.6366 1.6633 1.6556 1.6492 45.629 50.475 53.66 69.292 47.566 3 3 2 3 3 "5d4a41890e604c00011ade8b" 24 35 37 9 14 14 15 3.7778 3.2308 2.8 1.5 1.507 1.7654 1.7436 1.7693 1.7111 99.816 55.985 66.808 75.172 75.723 1 3 3 3 3 "611b1d3794ac948af7e57e7a" 30 27 26 15 18 17 10 3.4444 3.7692 3.4 1.3333 1.6907 1.6672 1.6301 1.6394 1.6694 59.968 70.085 88.022 50.231 83.378 4 3 2 3 2 "5fd7782dee03dc08d3f3f491" 41 12 18 15 18 16 1 3.1667 3.5385 3.2 1 1.6699 1.7619 1.6189 1.6887 1.7252 43.024 82.113 79.512 85.408 94.488 3 2 2 2 1 "5b59a51fca6d01000157a8c3" 28 25 13 14 2 17 11 3.2222 3.2308 2.2 1 1.7773 1.739 1.6938 1.7503 1.6534 88.043 85.023 90.143 86.182 90.322 2 2 1 2 1 "5eac84ff4efbe80ffd3962f1" 36 20 19 16 13 18 6 3.6667 3.2308 3.2 1 1.6355 0 1.6834 1.6654 1.6764 51.777 0 66.512 61.776 68.834 4 0 3 2 3 "5e92f01a49a5ba62bd0d5693" 26 17 20 18 15 14 7 3.9444 3.9231 4.2 1.6667 1.6839 1.7069 1.6936 1.6896 1.6451 75.459 48.576 86.224 76.887 77.439 3 3 2 3 2 "5f5e7de4c81d3672642cd612" 30 31 26 10 25 15 21 3.6111 3.0769 3.6 1 1.6836 1.7604 1.7792 1.7314 1.7729 61.36 89.324 87.999 87.996 91.276 3 2 2 2 1 "5ecbb2347a5125043b1d3588" 29 21 26 15 26 17 13 3.4444 3.1538 2.8 3.6667 1.5699 1.6717 1.63 1.5626 1.5613 76.414 89.3 83.723 57.282 85.121 3 2 2 3 2
I get this error:
Left and right key variables 'ID' and 'ID' are not comparable because one is a non-cell.
This issue didnt arise with other tables which I joined like the following:
DFA_PCA_table = join(high_dfa_ID_table,PCA_table)
DFA_PCA_table = 17×16 table
ID DFA_phase_1 DFA_phase_2 DFA_phase_3 DFA_phase_4 DFA_phase_5 PCA1_phase_1 PCA1_phase_2 PCA1_phase_3 PCA2_phase_4 PCA2_phase_5 PCA2_phase_1 PCA2_phase_2 PCA2_phase_3 comptable_high_pca_2_ID5 comptable_high_pca_2_ID6 ____________________________ ___________ ___________ ___________ ___________ ___________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ________________________ ________________________ {'5b59a51fca6d01000157a8c3'} 1.7773 1.739 1.6938 1.7503 1.6534 88.043 85.023 90.143 86.182 90.322 2 2 1 2 1 {'5d4a41890e604c00011ade8b'} 1.507 1.7654 1.7436 1.7693 1.7111 99.816 55.985 66.808 75.172 75.723 1 3 3 3 3 {'5dc4bc30569be3387eb6b52f'} 1.5251 1.6366 1.6633 1.6556 1.6492 45.629 50.475 53.66 69.292 47.566 3 3 2 3 3 {'5e92f01a49a5ba62bd0d5693'} 1.6839 1.7069 1.6936 1.6896 1.6451 75.459 48.576 86.224 76.887 77.439 3 3 2 3 2 {'5eac84ff4efbe80ffd3962f1'} 1.6355 0 1.6834 1.6654 1.6764 51.777 0 66.512 61.776 68.834 4 0 3 2 3 {'5ecbb2347a5125043b1d3588'} 1.5699 1.6717 1.63 1.5626 1.5613 76.414 89.3 83.723 57.282 85.121 3 2 2 3 2 {'5f5e7de4c81d3672642cd612'} 1.6836 1.7604 1.7792 1.7314 1.7729 61.36 89.324 87.999 87.996 91.276 3 2 2 2 1 {'5f5503435d41a489068ff50b'} 1.6466 1.6342 1.6335 1.6368 1.7084 59.128 50.854 51.244 66.032 51.386 4 4 4 3 4 {'5fb6ed2116919c000a99249e'} 1.6919 1.7101 1.6341 1.6829 1.6828 64.623 62.614 44.905 81.629 68.942 3 3 4 2 2 {'5fd7782dee03dc08d3f3f491'} 1.6699 1.7619 1.6189 1.6887 1.7252 43.024 82.113 79.512 85.408 94.488 3 2 2 2 1 {'607ed750ad800928b1861317'} 1.6211 1.7707 1.7568 1.7421 1.7598 65.881 64.797 40.056 61.687 59.588 4 3 4 3 2 {'611b1d3794ac948af7e57e7a'} 1.6907 1.6672 1.6301 1.6394 1.6694 59.968 70.085 88.022 50.231 83.378 4 3 2 3 2 {'614ec4f7be36eb900905644c'} 1.4783 1.6334 1.6725 1.6926 1.6961 99.961 83.792 89.069 84.172 94.264 1 2 2 2 1 {'6134c80f7eab0971588b3d3a'} 1.5811 1.6629 1.7217 1.7476 1.726 76.684 80.856 78.872 70.078 80.126 3 2 2 3 3 {'6155c449ebffeae654abd854'} 1.6249 1.6795 1.63 1.659 1.642 44.8 76.618 84.346 83.478 58.59 4 2 2 2 3 {'61520b079436973e05f72d33'} 1.6276 1.6811 1.6317 1.6948 1.607 60.351 92.232 77.059 61.229 63.239 4 1 4 3 3
Any idea why that is the case?
Thanks!
EDIT: mat files reattached, variables loaded and code run to try to recreate the error
  6 Comments
Image Analyst
Image Analyst on 28 Jul 2022
To avoid spam, there may be a limit on how many posts a new user can make per day (10 I think). Try again tomorrow.
Cris LaPierre
Cris LaPierre on 28 Jul 2022
Edited: Cris LaPierre on 28 Jul 2022
You might be able to edit your original question, too, as the data and some code have already been added there. I've edited it to re-add the mat files and have run the code you shared.

Sign in to comment.

Answers (1)

Gyan Vaibhav
Gyan Vaibhav on 8 Nov 2023
Hi lil brain,
I understand from your issue that you are unable to join two tables, that have a common column named “ID”, and you are prompted with an error you mentioned above.
From MATLAB R2022a onwards, the “join” function can handle key variables with different data types (like string arrays and cell arrays of character vectors). So, your original code should work as expected without any modifications in MATLAB R2022a and later versions.
However, in MATLAB R2021b and earlier versions, the “join” function requires key variables to have the same data type. If you encounter the error "Left and right key variables 'ID' and 'ID' are not comparable because one is a non-cell", it means that the 'ID' column in one table is a cell array of character vectors while in the other table it's a string array.
You can resolve this issue by converting the 'ID' column to the same data type in both tables. If the 'ID' column is an alphanumeric string, you should convert the string array to a cell array of character vectors using the “cellstr” function.
Here is the modified code where I have simply converted the string variables to cell array.
load questionnaire_table.mat
load DFA_PCA_table.mat
load high_dfa_ID_table.mat
load PCA_table.mat
% Convert 'ID' column to cell array of character vectors if it's a string array in questionnaire_table
if isstring(questionnaire_table.ID)
questionnaire_table.ID = cellstr(questionnaire_table.ID);
end
% Now you can join the tables
Full_high_data_set_table = join(questionnaire_table,DFA_PCA_table)
Full_high_data_set_table = 17×27 table
ID loc_internal_locus_of_control loc_powerful_others loc_chance empathy_perspective_taking empath_fantasy empathy_empathic_concern empathy_personal_distress itc_spatial_presence itc_engagement itc_ecological_validity itc_negative_effects_rows DFA_phase_1 DFA_phase_2 DFA_phase_3 DFA_phase_4 DFA_phase_5 PCA1_phase_1 PCA1_phase_2 PCA1_phase_3 PCA2_phase_4 PCA2_phase_5 PCA2_phase_1 PCA2_phase_2 PCA2_phase_3 comptable_high_pca_2_ID5 comptable_high_pca_2_ID6 ____________________________ _____________________________ ___________________ __________ __________________________ ______________ ________________________ _________________________ ____________________ ______________ _______________________ _________________________ ___________ ___________ ___________ ___________ ___________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ________________________ ________________________ {'61520b079436973e05f72d33'} 31 23 26 18 12 14 16 3.3333 3.4615 2.4 1 1.6276 1.6811 1.6317 1.6948 1.607 60.351 92.232 77.059 61.229 63.239 4 1 4 3 3 {'5f5503435d41a489068ff50b'} 28 18 21 17 19 15 11 3.2222 3.2308 2.8 2 1.6466 1.6342 1.6335 1.6368 1.7084 59.128 50.854 51.244 66.032 51.386 4 4 4 3 4 {'61728b3e4e680d6c607f514c'} 10 33 24 8 18 14 22 4.1111 4.2308 3.8 1.1667 1.5956 1.7259 1.6352 1.7089 1.6748 52.065 67.773 93.596 50.603 91.444 4 2 1 3 1 {'614ec4f7be36eb900905644c'} 41 13 24 25 11 17 7 3.7778 3.9231 3.4 1.6667 1.4783 1.6334 1.6725 1.6926 1.6961 99.961 83.792 89.069 84.172 94.264 1 2 2 2 1 {'6155c449ebffeae654abd854'} 12 31 37 16 22 9 5 2.9444 3.0769 3.2 2.6667 1.6249 1.6795 1.63 1.659 1.642 44.8 76.618 84.346 83.478 58.59 4 2 2 2 3 {'6134c80f7eab0971588b3d3a'} 36 12 22 11 13 14 10 4.0556 4.3077 4.8 1.5 1.5811 1.6629 1.7217 1.7476 1.726 76.684 80.856 78.872 70.078 80.126 3 2 2 3 3 {'5fb6ed2116919c000a99249e'} 33 34 37 13 23 16 19 3.5556 3.6154 3.6 1 1.6919 1.7101 1.6341 1.6829 1.6828 64.623 62.614 44.905 81.629 68.942 3 3 4 2 2 {'5dc4bc30569be3387eb6b52f'} 15 17 32 10 18 17 25 3 3.7692 2.6 1.1667 1.5251 1.6366 1.6633 1.6556 1.6492 45.629 50.475 53.66 69.292 47.566 3 3 2 3 3 {'5d4a41890e604c00011ade8b'} 24 35 37 9 14 14 15 3.7778 3.2308 2.8 1.5 1.507 1.7654 1.7436 1.7693 1.7111 99.816 55.985 66.808 75.172 75.723 1 3 3 3 3 {'611b1d3794ac948af7e57e7a'} 30 27 26 15 18 17 10 3.4444 3.7692 3.4 1.3333 1.6907 1.6672 1.6301 1.6394 1.6694 59.968 70.085 88.022 50.231 83.378 4 3 2 3 2 {'5fd7782dee03dc08d3f3f491'} 41 12 18 15 18 16 1 3.1667 3.5385 3.2 1 1.6699 1.7619 1.6189 1.6887 1.7252 43.024 82.113 79.512 85.408 94.488 3 2 2 2 1 {'5b59a51fca6d01000157a8c3'} 28 25 13 14 2 17 11 3.2222 3.2308 2.2 1 1.7773 1.739 1.6938 1.7503 1.6534 88.043 85.023 90.143 86.182 90.322 2 2 1 2 1 {'5eac84ff4efbe80ffd3962f1'} 36 20 19 16 13 18 6 3.6667 3.2308 3.2 1 1.6355 0 1.6834 1.6654 1.6764 51.777 0 66.512 61.776 68.834 4 0 3 2 3 {'5e92f01a49a5ba62bd0d5693'} 26 17 20 18 15 14 7 3.9444 3.9231 4.2 1.6667 1.6839 1.7069 1.6936 1.6896 1.6451 75.459 48.576 86.224 76.887 77.439 3 3 2 3 2 {'5f5e7de4c81d3672642cd612'} 30 31 26 10 25 15 21 3.6111 3.0769 3.6 1 1.6836 1.7604 1.7792 1.7314 1.7729 61.36 89.324 87.999 87.996 91.276 3 2 2 2 1 {'5ecbb2347a5125043b1d3588'} 29 21 26 15 26 17 13 3.4444 3.1538 2.8 3.6667 1.5699 1.6717 1.63 1.5626 1.5613 76.414 89.3 83.723 57.282 85.121 3 2 2 3 2
% Convert 'ID' column to cell array of character vectors if it's a string array in PCA_table
if isstring(PCA_table.ID)
PCA_table.ID = cellstr(PCA_table.ID);
end
% Now you can join the tables
DFA_PCA_table = join(high_dfa_ID_table,PCA_table)
DFA_PCA_table = 17×16 table
ID DFA_phase_1 DFA_phase_2 DFA_phase_3 DFA_phase_4 DFA_phase_5 PCA1_phase_1 PCA1_phase_2 PCA1_phase_3 PCA2_phase_4 PCA2_phase_5 PCA2_phase_1 PCA2_phase_2 PCA2_phase_3 comptable_high_pca_2_ID5 comptable_high_pca_2_ID6 ____________________________ ___________ ___________ ___________ ___________ ___________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ________________________ ________________________ {'5b59a51fca6d01000157a8c3'} 1.7773 1.739 1.6938 1.7503 1.6534 88.043 85.023 90.143 86.182 90.322 2 2 1 2 1 {'5d4a41890e604c00011ade8b'} 1.507 1.7654 1.7436 1.7693 1.7111 99.816 55.985 66.808 75.172 75.723 1 3 3 3 3 {'5dc4bc30569be3387eb6b52f'} 1.5251 1.6366 1.6633 1.6556 1.6492 45.629 50.475 53.66 69.292 47.566 3 3 2 3 3 {'5e92f01a49a5ba62bd0d5693'} 1.6839 1.7069 1.6936 1.6896 1.6451 75.459 48.576 86.224 76.887 77.439 3 3 2 3 2 {'5eac84ff4efbe80ffd3962f1'} 1.6355 0 1.6834 1.6654 1.6764 51.777 0 66.512 61.776 68.834 4 0 3 2 3 {'5ecbb2347a5125043b1d3588'} 1.5699 1.6717 1.63 1.5626 1.5613 76.414 89.3 83.723 57.282 85.121 3 2 2 3 2 {'5f5e7de4c81d3672642cd612'} 1.6836 1.7604 1.7792 1.7314 1.7729 61.36 89.324 87.999 87.996 91.276 3 2 2 2 1 {'5f5503435d41a489068ff50b'} 1.6466 1.6342 1.6335 1.6368 1.7084 59.128 50.854 51.244 66.032 51.386 4 4 4 3 4 {'5fb6ed2116919c000a99249e'} 1.6919 1.7101 1.6341 1.6829 1.6828 64.623 62.614 44.905 81.629 68.942 3 3 4 2 2 {'5fd7782dee03dc08d3f3f491'} 1.6699 1.7619 1.6189 1.6887 1.7252 43.024 82.113 79.512 85.408 94.488 3 2 2 2 1 {'607ed750ad800928b1861317'} 1.6211 1.7707 1.7568 1.7421 1.7598 65.881 64.797 40.056 61.687 59.588 4 3 4 3 2 {'611b1d3794ac948af7e57e7a'} 1.6907 1.6672 1.6301 1.6394 1.6694 59.968 70.085 88.022 50.231 83.378 4 3 2 3 2 {'614ec4f7be36eb900905644c'} 1.4783 1.6334 1.6725 1.6926 1.6961 99.961 83.792 89.069 84.172 94.264 1 2 2 2 1 {'6134c80f7eab0971588b3d3a'} 1.5811 1.6629 1.7217 1.7476 1.726 76.684 80.856 78.872 70.078 80.126 3 2 2 3 3 {'6155c449ebffeae654abd854'} 1.6249 1.6795 1.63 1.659 1.642 44.8 76.618 84.346 83.478 58.59 4 2 2 2 3 {'61520b079436973e05f72d33'} 1.6276 1.6811 1.6317 1.6948 1.607 60.351 92.232 77.059 61.229 63.239 4 1 4 3 3
Alternatively, you can upgrade to any newer version or use MATLAB online.
Hope this helps and resolves your issue.
Thanks
Gyan

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!