我有从文本文件中读取的列表,我想分开这个字符串,我发现这可以用read.table完成(仍在尝试)。在这里我尝试了'单独',现在我想知道错误参数是什么意思?
STN.....TIME.TMP.DEW.RH..DIR.SPD.VIS..CLOUDS
1 DD/HHMM C C % deg m/s km
2 ==== ======= === === === === === ==== ======= ======= =======
3 WMAU 02/0000 23 23 100 260 2 3.0 FEW*** BKN140 BKN270
4 WMAU 01/2300
5 WMAU 01/2200
6 WMAU 01/2100
7 WMAU 01/2000
8 WMAU 01/1900
9 WMAU 01/1800
10 WMAU 01/1700
11 WMAU 01/1600
12 WMAU 01/1500
13 WMAU 01/1400
14 WMAU 01/1300
15 WMAU 01/1200
16 WMAU 01/1100
17 WMAU 01/1000
18 WMAU 01/0900
19 WMAU 01/0800 28 26 89 30 3 10.0 FEW020 SCT140 BKN270
20 WMAU 01/0700 27 25 89 90 3 10.0 SCT020 BKN140 BKN270
21 WMAU 01/0600 27 26 94 50 2 10.0 FEW017 SCT020 BKN140
22 WMAU 01/0500 28 26 89 90 2 10.0 FEW017 SCT020 BKN270
23 WMAU 01/0400 30 27 84 60 2 10.0 FEW017 SCT020 BKN270
24 WMAU 01/0300 30 26 79 90 2 10.0 FEW017 SCT020 BKN270
25 WMAU 01/0200 29 27 89 270 2 10.0 FEW017 SCT140 BKN270
26 WMAU 01/0100 26 25 94 260 2 10.0 FEW010 SCT140 BKN270
27 WMAU 01/0000 24 24 100 270 2 8.0 FEW*** SCT140 BKN270
要使用'separate',我知道早期行无法完成,因为它缺少元素,所以我从第19行开始采用数据。
datan <- read.table("C:/Users/NARC/Documents/Saleha/mersing.txt", skip = 25)
> str(datan)
'data.frame': 8 obs. of 11 variables:
$ V1 : Factor w/ 1 level "WMAU": 1 1 1 1 1 1 1 1
$ V2 : Factor w/ 8 levels "01/0000","01/0100",..: 8 7 6 5 4 3 2 1
$ V3 : int 27 27 28 30 30 29 26 24
$ V4 : int 25 26 26 27 26 27 25 24
$ V5 : int 89 94 89 84 79 89 94 100
$ V6 : int 90 50 90 60 90 270 260 270
$ V7 : int 3 2 2 2 2 2 2 2
$ V8 : num 10 10 10 10 10 10 10 8
$ V9 : Factor w/ 4 levels "FEW***","FEW010",..: 4 3 3 3 3 3 2 1
$ V10: Factor w/ 3 levels "BKN140","SCT020",..: 1 2 2 2 2 3 3 3
$ V11: Factor w/ 2 levels "BKN140","BKN270": 2 1 2 2 2 2 2 2
df %>% separate (datan, c('STN','TIME', 'TMP', 'DEW', 'RH', 'DIR', 'SPD', 'VIS', 'CLOUDS'),sep = "\t")
错误:
Error in if (!after) c(values, x) else if (after >= lengx) c(x, values) else c(x[1L:after], : argument is of length zero