Effacer les filtres
Effacer les filtres

Merge columns with different cell input

1 vue (au cours des 30 derniers jours)
Jennifer March
Jennifer March le 9 Juin 2021
Modifié(e) : Jennifer March le 11 Juin 2021
How can I merge two columns where cells have different information?
Specifically I would like to merge the last two columns (lets call them F and G) into column H. In the example below F consists of a 1x5 table whereas G is ''. I have multiple tables like this, where F and G have the following information:
  1. either F Table and G '' (shortened example below)
  2. or G Table and F ''
  3. or both Table
In case of 3., I would like to merge the two in a long format., such that each row is double.
'floor_csv' '5610002' 'Male' 12.8300000000000 16.2200000000000 1x5 table ''
'floor_csv' '5610004' 'Female' 47.8300000000000 28.5500000000000 1x5 table ''
'floor_csv' '5610005' 'Female' 13.7500000000000 16.1400000000000 1x5 table ''
I only came up with H = [F; G], which did not work.
Any help is appreciated!

Réponses (1)

Duncan Po
Duncan Po le 9 Juin 2021
Can you convert your empty char '' into empty array []? Tables can be concatenated with empty array but not empty char:
t = table([1; 2]); c = ''; a = [];
[t c]
All input arguments must be tables.
[t a]
ans =
2×1 table
  1 commentaire
Jennifer March
Jennifer March le 11 Juin 2021
Modifié(e) : Jennifer March le 11 Juin 2021
I am still stuck on replacing it, here my code. I guess the problem is that the table I am working with (subjects) is nested in another table (df). The column is called 'food_nonfood
for i = 1:length(df.subjects)
if df.subjects.food_nonfood == ''
replace(df.subjects.food_nonfood, '', [])

Connectez-vous pour commenter.


En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by