您应该(始终)尝试重新组织您的数据,以便每一列都包含一种类型的信息:
Year Month Lat Lon Value
python 脚本可能是执行此操作的最佳方式...一旦您拥有这种风格的脚本,就可以很容易地在 R 中导入和分析。
我制作了一个脚本,它将为您重新组织您的数据...但不清楚您是否可以轻松运行它。你用的是什么系统?
这是脚本...输出如下...
#!/usr/bin/env python
import csv
file_obj = open('originaldata.txt', 'r')
Input = csv.reader(file_obj, delimiter='\t')
LineNo = 0
year,month,data = [],[],[]
for items in Input:
if LineNo == 0:
lat = items[2:]
elif LineNo == 1:
lon = items[2:]
else:
year.append(items[0])
month.append(items[1])
data.append(items[2:])
LineNo += 1
# print header
print "%s\t%s\t%s\t%s\t%s"% ("Year","Month","Lat","Lon","Data")
for La,Lo,Ind in zip(lat,lon,range(len(lat))):
for Y,M,D in zip(year,month,data):
print "%s\t%s\t%s\t%s\t%s"% (Y,M,La,Lo,D[Ind])
脚本的输出:
Year Month Lat Lon Data
1980 1 31.5 -111.5 0
1980 2 31.5 -111.5 0
1980 3 31.5 -111.5 0
1980 4 31.5 -111.5 0
1980 5 31.5 -111.5 8.1
1980 6 31.5 -111.5 5.1
1980 7 31.5 -111.5 0
1980 8 31.5 -111.5 0
1980 9 31.5 -111.5 0
1980 10 31.5 -111.5 0
1980 11 31.5 -111.5 0
1980 12 31.5 -111.5 0
1981 1 31.5 -111.5 0
1981 2 31.5 -111.5 0
1981 3 31.5 -111.5 0
1981 4 31.5 -111.5 0
1981 5 31.5 -111.5 0
1981 6 31.5 -111.5 0
1981 7 31.5 -111.5 0
1981 8 31.5 -111.5 0
1981 9 31.5 -111.5 0
1981 10 31.5 -111.5 0
1981 11 31.5 -111.5 0
1981 12 31.5 -111.5 0
1980 1 31.5 -110.5 0
1980 2 31.5 -110.5 0
1980 3 31.5 -110.5 0
1980 4 31.5 -110.5 881
1980 5 31.5 -110.5 794.1
1980 6 31.5 -110.5 644.4
1980 7 31.5 -110.5 85.2
1980 8 31.5 -110.5 0.1
1980 9 31.5 -110.5 0
1980 10 31.5 -110.5 0
1980 11 31.5 -110.5 0
1980 12 31.5 -110.5 0
1981 1 31.5 -110.5 0
1981 2 31.5 -110.5 0
1981 3 31.5 -110.5 0
1981 4 31.5 -110.5 0
1981 5 31.5 -110.5 0
1981 6 31.5 -110.5 0
1981 7 31.5 -110.5 0
1981 8 31.5 -110.5 0
1981 9 31.5 -110.5 0
1981 10 31.5 -110.5 0