フィルターのクリア

Resorting Rows in a Table with Panel Data

1 回表示 (過去 30 日間)
Saunok Chakrabarty
Saunok Chakrabarty 2021 年 4 月 13 日
コメント済み: Saunok Chakrabarty 2021 年 4 月 16 日
Hello,
I exported a table from Excel to Matlab. The file contains variables in panel data format, sorted by Country and Year. My time period stretches from 1990-2017. I had initially constructed the table from 1995-2017, and then at the end, I'd added the data from 1990-1994, again sorted by Country and Year (I did not need these time periods initially). So it is this way now:
Country 1 1995
Country 1 1996
...
Country 180 2017
Country 1 1990
Country 1 1991
Country 1 1992
Country 1 1993
Country 1 1994
Country 2 1990
....
Is it possible for me to rearrange the data in a way so that the entire dataset runs from 1990-2017, by Country and Year?
Regards,
Saunok

採用された回答

Adam Danz
Adam Danz 2021 年 4 月 14 日
編集済み: Adam Danz 2021 年 4 月 14 日
See sortrows.
If there are any problems implementing that function, show us what you've got and we can help straighten it out.
  4 件のコメント
Adam Danz
Adam Danz 2021 年 4 月 15 日
Saunok Chakrabarty you're absolutely correct. I forgot that inputs must be the same size or one can be scalar with strcmp/i. Sorry to have mislead you. I'll remove those comments to prevent future visitors from getting confused.
To make up for my mistake I'll offer one improvement of your otherwise perfectly fine solution to use ismember. Most of the time string matches are not case sensitive but with ismember, "Zambia" will not match with "zambia".
ismember({'Afghanistan','Zambia'}, 'zambia')
ans = 1×2 logical array
0 0
To allow for case sensitivity, force all strings to upper or lower case:
ismember(lower({'Afghanistan','Zambia'}), lower('zambia'))
ans = 1×2 logical array
0 1
Saunok Chakrabarty
Saunok Chakrabarty 2021 年 4 月 16 日
Hi Adam,
Thanks a ton for this suggestion. I'm actually new to Matlab so this helps iron out my confusions.
Regards,
Saunok

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by