私はRを初めて使用し、異なるデータセット間にヘッダーを付けて1つのファイルから多くのグラフを生成しようとしています。次のようにフォーマットされたタブ区切りのプレーンテキストファイルがあります。
Header: Boston city data
Month Data1 Data2 Data3
1 1.5 9.1342 8.1231
2 12.3 12.31 1.129
3 (etc...)
Header: Chicago city data
Month Data1 Data2 Data3
1 1.5 9.1342 8.1231
2 12.3 12.31 1.129
...
都市ごとに、月とData1、月とData2、月とData2のグラフを作成したいと思います。
Pythonでは、各行を繰り返し処理し、行が「Header」で始まる場合は別のことを実行してから、何らかの方法で数値を処理できることを知っています。私は単にこれをしたいと思います:
for (data block starting with header) in inf:
data = read.delim()
barplot(data, main=header, ylab="Data1", xlab="Month")
# repeat for Data2, Data3
しかし、実際にファイルを反復処理する方法がわかりません。または、ファイルを都市ごとに多数の小さなファイルに分割してから、小さなファイルのリストを実行して読み取る必要があるかどうかはわかりません。