在R中导入数据(read.table)

时间:2014-04-14 07:46:02

标签: r import read.table

我有以下文件,我想导入。

                   MONTHLY CLIMATOLOGICAL SUMMARY for MAR. 2014

NAME: larissa   CITY:    STATE:  
ELEV:    82 m  LAT:  39° 37' 39" N  LONG:  22° 23' 55" E

                   TEMPERATURE (°C), RAIN  (mm), WIND SPEED (km/hr)

                                      HEAT  COOL        AVG
    MEAN                              DEG   DEG         WIND                 DOM
DAY TEMP  HIGH   TIME   LOW    TIME   DAYS  DAYS  RAIN  SPEED HIGH   TIME    DIR
------------------------------------------------------------------------------------
 1   9.7  11.3   15:50   7.6    7:20   8.6   0.0   5.4   1.3  12.9   20:10   NNE
 2  11.8  16.9   14:50   9.8   00:00   6.5   0.0   4.2   2.7  24.1   13:30    NE
 3   9.3  11.5   14:20   7.9   00:00   9.0   0.0   6.0   0.8   9.7    3:00     N
 4  10.7  17.0   15:10   4.7    6:30   7.7   0.0   1.6   0.6  16.1   18:50    SW
 5  11.1  18.5   14:40   6.0    7:30   7.3   0.0   0.2   1.1  16.1   18:50   SSW
 6  10.9  16.9   13:50   5.1    6:30   7.4   0.0   0.0   1.1  16.1   16:20   ENE
 7  11.3  13.8   14:20  10.1    9:00   7.1   0.0   7.0   3.9  25.7    4:20   NNE
 8  12.1  16.6   14:00   9.4    8:00   6.2   0.0   2.8   1.8  22.5   22:40   ENE
 9   9.0  10.4   13:10   7.6   00:00   9.3   0.0   0.4   1.8  27.4   10:40   NNE
10   7.9  10.1   13:50   6.6   23:50  10.4   0.0   1.0   4.0  24.1   20:20    NE
11   7.8  10.1   14:20   5.4    5:30  10.6   0.0   0.8   1.1  16.1   11:00     N
12  11.3  18.7   15:30   6.8    7:10   7.0   0.0   0.0   1.3  20.9   14:20    SW
13  11.3  19.1   16:00   4.5    7:40   7.1   0.1   0.0   0.6  12.9   13:10   WSW
14  11.7  20.1   15:40   5.1    6:30   6.8   0.2   0.0   0.6  11.3   15:00   WNW
15  12.6  21.1   15:40   5.2    7:10   6.1   0.3   0.0   0.5   9.7   14:10   SSW
16  14.6  22.3   15:40   8.3    7:10   4.4   0.7   0.0   1.1  11.3   10:40   ENE
17  15.0  24.3   15:10   7.1    6:10   4.6   1.3   0.0   1.0  12.9    7:10   ENE
18  16.0  26.9   15:40   7.2    6:40   4.2   1.9   0.0   0.6  11.3   15:00   SSE
19  17.7  28.4   15:10   8.2    6:50   3.3   2.7   0.0   1.8  24.1   23:40    SW
20  16.6  22.5   16:00  11.1   00:00   2.6   0.8   0.0   2.7  24.1    7:50     N
21  13.8  21.9   16:30   6.7    6:20   5.0   0.6   0.0   0.8  16.1   14:50   ENE
22  14.3  24.1   15:40   5.8    5:40   4.9   0.9   0.0   0.5   9.7   13:50    SW
23  16.4  25.7   16:00   9.8    7:40   3.5   1.6   0.0   0.5   9.7   13:30   ESE
24  16.3  24.9   14:50  10.2    6:10   3.2   1.1   0.0   2.4  29.0   16:10   SSW
25  14.1  21.0   15:40   9.2    6:40   4.5   0.3   0.0   3.9  32.2   14:50    SW
26  12.9  19.0   16:20   9.6    6:10   5.4   0.0   1.6   1.0  12.9   12:50     N
27  14.3  19.2   13:50  11.3    2:30   4.1   0.1   0.2   3.2  33.8   14:20   ENE
28  13.1  19.0   15:40   7.4    6:30   5.3   0.0   0.4   1.4  17.7   15:50    SW
29  14.7  21.2   15:10  10.8    5:40   3.9   0.3   0.2   1.3  19.3   11:30   ENE
30  12.6  17.2   15:30   9.2   00:00   5.4   0.0   0.0   2.6  25.7    4:00   ENE
31  13.1  23.0   17:00   5.2    7:30   6.0   0.7   0.0   0.5   8.0   14:50    SW
-------------------------------------------------------------------------------------
    12.7  28.4    19     4.5    13   187.4  13.5  31.8   1.6  33.8    27     ENE

Max >=  32.0:  0
Max <=   0.0:  0
Min <=   0.0:  0
Min <= -18.0:  0
Max Rain: 7.01 ON 07/03/14
Days of Rain: 14 (> .2 mm) 5 (> 2 mm) 0 (> 20 mm)
Heat Base:  18.3  Cool Base:  18.3  Method: Integration

只需尝试使用read.table header=T, dec=".", sep=""作为附加参数,我就会收到此错误:

Error in read.table("C:\\blablabla\\file.txt)
  more columns than column names
Execution halted

我认为该文件不是\t分开的,而是""。我也在想这可能是由于桌前的额外文字造成的。 read.csv会有所作为吗?

有什么建议吗?提前谢谢。

1 个答案:

答案 0 :(得分:3)

问题在于列名称上方列出了一些其他信息。简单地跳过这将解决您的问题。为此,您可以使用属于skip的<{1}}参数。

read.csv