我在桌面上保存了一个名为“windmillData”的txt文件。这是如何在txt文档中格式化数据的片段 数据分析候选地点“Cspd”(y变量)的风速,并比较参考地点“Rspd”(x变量)的风速
Date Cspd Rspd
"2002/1/1/0" 6.9 5.9666
"2002/1/1/6" 7.1 7.2176
"2002/1/1/12" 7.8 7.9405
"2002/1/1/18" 6.9 6.0174
"2002/1/2/0" 5.5 6.1646
"2002/1/2/6" 3.1 1.7687
"2002/1/2/12" 6.8 4.6471
"2002/1/2/18" 11.4 10.8734
"2002/1/3/0" 12.9 11.7198
"2002/1/3/6" 13.5 13.0118
"2002/1/3/12" 9.6 6.3998
"2002/1/3/18" 8.0 8.2706
"2002/1/4/0" 8.3 8.3522
"2002/1/4/6" 8.8 7.9027
"2002/1/4/12" 6.1 6.7136
"2002/1/4/18" 8.4 9.6341
"2002/1/5/0" 8.5 8.7918
"2002/1/5/6" 9.6 10.2506
"2002/1/5/12" 10.4 10.8894
"2002/1/5/18" 10.0 7.6393
"2002/1/6/0" 10.6 8.2217
"2002/1/6/6" 8.9 7.4820
"2002/1/6/12" 9.4 9.2628
"2002/1/6/18" 8.8 4.8476
"2002/1/7/0" 6.1 4.4194
"2002/1/7/6" 13.5 11.3922
"2002/1/7/12" 11.5 10.6574
"2002/1/7/18" 9.9 9.2053
"2002/1/8/0" 10.5 11.2537
"2002/1/8/6" 11.7 13.2537
"2002/1/8/12" 11.2 8.6108
我一直在尝试将数据加载到R中,但我似乎无法让它工作。
> read.table(file = "windmillData.txt", sep=",")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'windmillData.txt': No such file or directory
> read.table(file = "windmillData.txt", sep="/t",header=TRUE)
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'windmillData.txt': No such file or directory
帮助将不胜感激。谢谢!
答案 0 :(得分:0)
就像RStudent回复一样,你应该确定你的目录在哪里(可能是Documents)。但是,您不需要将文件放在工作目录中或更改目录。您可以将文件加载为:
read.table(' C:\ Users \ user \ Documents \ windmillData.txt',sep =" / t")
答案 1 :(得分:0)
已在下面的代码中加载:
> ddf = read.table(text='
+ Date Cspd Rspd
+ "2002/1/1/0" 6.9 5.9666
+ "2002/1/1/6" 7.1 7.2176
+ "2002/1/1/12" 7.8 7.9405
+ "2002/1/1/18" 6.9 6.0174
+ "2002/1/2/0" 5.5 6.1646
+ "2002/1/2/6" 3.1 1.7687
+ "2002/1/2/12" 6.8 4.6471
+ "2002/1/2/18" 11.4 10.8734
+ "2002/1/3/0" 12.9 11.7198
+ "2002/1/3/6" 13.5 13.0118
+ "2002/1/3/12" 9.6 6.3998
+ "2002/1/3/18" 8.0 8.2706
+ "2002/1/4/0" 8.3 8.3522
+ "2002/1/4/6" 8.8 7.9027
+ "2002/1/4/12" 6.1 6.7136
+ "2002/1/4/18" 8.4 9.6341
+ "2002/1/5/0" 8.5 8.7918
+ "2002/1/5/6" 9.6 10.2506
+ "2002/1/5/12" 10.4 10.8894
+ "2002/1/5/18" 10.0 7.6393
+ "2002/1/6/0" 10.6 8.2217
+ "2002/1/6/6" 8.9 7.4820
+ "2002/1/6/12" 9.4 9.2628
+ "2002/1/6/18" 8.8 4.8476
+ "2002/1/7/0" 6.1 4.4194
+ "2002/1/7/6" 13.5 11.3922
+ "2002/1/7/12" 11.5 10.6574
+ "2002/1/7/18" 9.9 9.2053
+ "2002/1/8/0" 10.5 11.2537
+ "2002/1/8/6" 11.7 13.2537
+ "2002/1/8/12" 11.2 8.6108
+ ', header=T)
>
> ddf
Date Cspd Rspd
1 2002/1/1/0 6.9 5.9666
2 2002/1/1/6 7.1 7.2176
3 2002/1/1/12 7.8 7.9405
4 2002/1/1/18 6.9 6.0174
5 2002/1/2/0 5.5 6.1646
6 2002/1/2/6 3.1 1.7687
7 2002/1/2/12 6.8 4.6471
8 2002/1/2/18 11.4 10.8734
9 2002/1/3/0 12.9 11.7198
10 2002/1/3/6 13.5 13.0118
11 2002/1/3/12 9.6 6.3998
12 2002/1/3/18 8.0 8.2706
13 2002/1/4/0 8.3 8.3522
14 2002/1/4/6 8.8 7.9027
15 2002/1/4/12 6.1 6.7136
16 2002/1/4/18 8.4 9.6341
17 2002/1/5/0 8.5 8.7918
18 2002/1/5/6 9.6 10.2506
19 2002/1/5/12 10.4 10.8894
20 2002/1/5/18 10.0 7.6393
21 2002/1/6/0 10.6 8.2217
22 2002/1/6/6 8.9 7.4820
23 2002/1/6/12 9.4 9.2628
24 2002/1/6/18 8.8 4.8476
25 2002/1/7/0 6.1 4.4194
26 2002/1/7/6 13.5 11.3922
27 2002/1/7/12 11.5 10.6574
28 2002/1/7/18 9.9 9.2053
29 2002/1/8/0 10.5 11.2537
30 2002/1/8/6 11.7 13.2537
31 2002/1/8/12 11.2 8.6108
>
> dput(ddf)
structure(list(Date = structure(c(1L, 4L, 2L, 3L, 5L, 8L, 6L,
7L, 9L, 12L, 10L, 11L, 13L, 16L, 14L, 15L, 17L, 20L, 18L, 19L,
21L, 24L, 22L, 23L, 25L, 28L, 26L, 27L, 29L, 31L, 30L), .Label = c("2002/1/1/0",
"2002/1/1/12", "2002/1/1/18", "2002/1/1/6", "2002/1/2/0", "2002/1/2/12",
"2002/1/2/18", "2002/1/2/6", "2002/1/3/0", "2002/1/3/12", "2002/1/3/18",
"2002/1/3/6", "2002/1/4/0", "2002/1/4/12", "2002/1/4/18", "2002/1/4/6",
"2002/1/5/0", "2002/1/5/12", "2002/1/5/18", "2002/1/5/6", "2002/1/6/0",
"2002/1/6/12", "2002/1/6/18", "2002/1/6/6", "2002/1/7/0", "2002/1/7/12",
"2002/1/7/18", "2002/1/7/6", "2002/1/8/0", "2002/1/8/12", "2002/1/8/6"
), class = "factor"), Cspd = c(6.9, 7.1, 7.8, 6.9, 5.5, 3.1,
6.8, 11.4, 12.9, 13.5, 9.6, 8, 8.3, 8.8, 6.1, 8.4, 8.5, 9.6,
10.4, 10, 10.6, 8.9, 9.4, 8.8, 6.1, 13.5, 11.5, 9.9, 10.5, 11.7,
11.2), Rspd = c(5.9666, 7.2176, 7.9405, 6.0174, 6.1646, 1.7687,
4.6471, 10.8734, 11.7198, 13.0118, 6.3998, 8.2706, 8.3522, 7.9027,
6.7136, 9.6341, 8.7918, 10.2506, 10.8894, 7.6393, 8.2217, 7.482,
9.2628, 4.8476, 4.4194, 11.3922, 10.6574, 9.2053, 11.2537, 13.2537,
8.6108)), .Names = c("Date", "Cspd", "Rspd"), class = "data.frame", row.names = c(NA,
-31L))
>