使用 read.table(text=“....") RStudio 加速在控制台中读取数据 [英] Speed up reading data in console using read.table(text="....") RStudio

查看:105
本文介绍了使用 read.table(text=“....") RStudio 加速在控制台中读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现自己从过去项目中存储的旧 Excel 文件中提取了一些数据.这些文件是无组织的,我的意思是没有通用的行和列格式,因此将整个电子表格直接读入 R 是没有用的,而且大多数时候我只想一次获取几列和几行数据.我发现获取数据的最简单方法是使用 read.table(text="....") 并将我想要的数据部分复制并粘贴到 text 中.这很好用,但是当我开始获取更大的数据集时,控制台需要更长的时间来处理信息.有时在输入非常大的函数时我会遇到同样的问题.我认为这可能是 RStudio 限制它显示在控制台中传递的信息的速度,但我不确定.我必须等待控制台传递此信息,然后才能做任何其他事情.如何让我的控制台向我显示我正在阅读的信息更快或根本不显示任何内容?最好是第一个.

I find myself pulling bits of data here and there from old excel files I have stored from past projects. These files are unorganized, I mean no common format of rows and columns so it would be useless to read the entire spreadsheet directly into R, and most of the time I just want to grab a couple columns and rows of data at a time anyway. Rather than creating a separate text file with the columns/rows I want and reading this file in I find the easiest way to get the data is to use read.table(text="....") and copy and paste the bit of data I want into text. This works great but when I start to grab larger data sets it takes longer for the console to process the information. I have the same issue sometimes when entering very large functions. I think this may be an RStudio limitation on how fast it shows the information passing in the console but I am not sure. I have to wait for the console to pass this information before I can do anything else. How can I get my console to either show me the information I'm reading faster or to not show me anything at all? Preferably the first.

示例数据

GNL <- read.table(header=TRUE,text="WYD Temp_C
1   12.77777778
2   11.66666667
3   8.888888889
4   3.888888889
5   -0.555555556
6   -1.111111111
7   3.888888889
8   7.777777778
9   8.333333333
10  6.666666667
11  10.55555556
12  15.55555556
13  16.11111111
14  16.66666667
15  15
16  13.33333333
17  14.44444444
18  13.88888889
19  11.66666667
20  12.77777778
21  12.22222222
22  15
23  14.44444444
24  11.11111111
25  7.222222222
26  5.555555556
27  6.666666667
28  8.888888889
29  11.66666667
30  11.66666667
31  10.55555556
32  7.777777778
33  8.333333333
34  2.777777778
35  -4.444444444
36  -5
37  -4.444444444
38  -1.666666667
39  0.555555556
40  5.555555556
41  NA
42  2.777777778
43  1.666666667
44  3.333333333
45  3.888888889
46  5
47  5.555555556
48  4.444444444
49  -1.111111111
50  -3.888888889
51  -3.888888889
52  -0.555555556
53  3.888888889
54  5.555555556
55  1.111111111
56  4.444444444
57  10
58  10
59  8.888888889
60  10
61  2.777777778
62  -3.333333333
63  1.666666667
64  -1.111111111
65  NA
66  NA
67  0
68  3.888888889
69  5
70  5.555555556
71  2.777777778
72  -0.555555556
73  -3.888888889
74  -3.333333333
75  -2.222222222
76  -1.666666667
77  3.888888889
78  6.111111111
79  1.666666667
80  2.222222222
81  5
82  3.333333333
83  0
84  4.444444444
85  5
86  5
87  5.555555556
88  6.111111111
89  8.888888889
90  7.222222222
91  5.555555556
92  7.777777778
93  10
94  8.888888889
95  9.444444444
96  11.11111111
97  8.888888889
98  6.111111111
99  5
100 7.777777778
101 7.777777778
102 5.555555556
103 6.111111111
104 5
105 6.111111111
106 5.555555556
107 0.555555556
108 -6.111111111
109 -2.222222222
110 2.777777778
111 1.666666667
112 2.222222222
113 -3.888888889
114 -3.333333333
115 NA
116 2.777777778
117 7.777777778
118 3.888888889
119 3.888888889
120 7.777777778
121 6.111111111
122 3.888888889
123 3.333333333
124 0.555555556
125 5.555555556
126 1.111111111
127 0.555555556
128 1.111111111
129 3.333333333
130 0
131 4.444444444
132 6.666666667
133 5
134 0
135 -1.111111111
136 -5.555555556
137 -2.777777778
138 -5
139 1.111111111
140 3.888888889
141 0
142 -2.222222222
143 0
144 6.666666667
145 8.333333333
146 8.888888889
147 7.777777778
148 2.777777778
149 -0.555555556
150 -5.555555556
151 -5.555555556
152 -5.555555556
153 -5
154 2.222222222
155 8.333333333
156 8.333333333
157 7.222222222
158 -5
159 -0.555555556
160 7.222222222
161 7.222222222
162 5
163 1.111111111
164 -0.555555556
165 -1.111111111
166 0
167 3.333333333
168 1.111111111
169 NA
170 -7.777777778
171 -6.666666667
172 NA
173 NA
174 NA
175 NA
176 2.777777778
177 -2.777777778
178 -2.777777778
179 NA
180 0.555555556
181 3.333333333
182 7.222222222
183 -0.555555556
184 -2.222222222
185 3.888888889
186 6.666666667
187 -1.111111111
188 -5.555555556
189 -1.666666667
190 6.111111111
191 7.777777778
192 7.777777778
193 3.888888889
194 -2.777777778
195 -3.333333333
196 -4.444444444
197 -2.777777778
198 3.333333333
199 6.111111111
200 6.666666667
201 7.222222222
202 11.11111111
203 13.88888889
204 15
205 15.55555556
206 13.88888889
207 10.55555556
208 7.222222222
209 2.222222222
210 4.444444444
211 8.888888889
212 11.11111111
213 11.11111111
214 8.888888889
215 8.333333333
216 5.555555556
217 5
218 6.666666667
219 10
220 11.66666667
221 12.77777778
222 13.88888889
223 12.77777778
224 12.22222222
225 14.44444444
226 16.11111111
227 10
228 10.55555556
229 NA
230 11.11111111
231 8.888888889
232 12.22222222
233 15.55555556
234 14.44444444
235 12.77777778
236 10
237 NA
238 NA
239 NA
240 NA
241 NA
242 NA
243 14.44444444
244 18.33333333
245 18.33333333
246 16.66666667
247 16.11111111
248 6.666666667
249 1.666666667
250 7.777777778
251 11.66666667
252 11.11111111
253 11.11111111
254 NA
255 15.55555556
256 16.11111111
257 16.11111111
258 16.11111111
259 17.22222222
260 22.22222222
261 21.11111111
262 17.22222222
263 16.11111111
264 18.33333333
265 16.11111111
266 11.11111111
267 7.777777778
268 9.444444444
269 8.888888889
270 10.55555556
271 13.33333333
272 15
273 14.44444444
274 14.44444444
275 14.44444444
276 15.55555556
277 16.11111111
278 16.11111111
279 16.11111111
280 17.22222222
281 19.44444444
282 19.44444444
283 20.55555556
284 22.22222222
285 22.22222222
286 22.22222222
287 19.44444444
288 18.33333333
289 17.22222222
290 15
291 12.22222222
292 13.33333333
293 13.88888889
294 17.77777778
295 20.55555556
296 21.11111111
297 19.44444444
298 17.22222222
299 17.22222222
300 17.22222222
301 16.11111111
302 15.55555556
303 17.77777778
304 19.44444444
305 19.44444444
306 20.55555556
307 21.66666667
308 22.22222222
309 18.88888889
310 19.44444444
311 19.44444444
312 21.11111111
313 22.22222222
314 22.77777778
315 22.77777778
316 23.88888889
317 23.33333333
318 23.33333333
319 21.11111111
320 21.11111111
321 21.11111111
322 21.11111111
323 18.88888889
324 20
325 20
326 18.88888889
327 18.33333333
328 17.77777778
329 18.88888889
330 18.88888889
331 15.55555556
332 16.66666667
333 17.77777778
334 18.88888889
335 19.44444444
336 15.55555556
337 13.88888889
338 16.11111111
339 17.22222222
340 18.33333333
341 18.33333333
342 16.11111111
343 17.77777778
344 19.44444444
345 19.44444444
346 17.77777778
347 16.11111111
348 17.77777778
349 19.44444444
350 18.88888889
351 18.33333333
352 17.22222222
353 16.66666667
354 NA
355 17.77777778
356 18.33333333
357 17.77777778
358 17.22222222
359 16.11111111
360 14.44444444
361 15
362 15.55555556
363 16.66666667
364 16.66666667
365 17.77777778
366 20")

推荐答案

如果问题真的只是信息在控制台中显示的时间,您可以直接获取文件:

If the problem is really just the time the information takes to be shown in the console, you could just source the file:

将您的 read.table 脚本保存在不同的 .R 文件中,然后执行 source("filepath/file.R", echo=FALSE).

Save you read.table script in a different .R file, and then just do source("filepath/file.R", echo=FALSE).

但我应该说,乍一看,以这种方式处理数据(手动复制和粘贴来自不同文件的不同数据位)并不是一个好主意.

But I should say that, at first glance, it doesn't look like a good idea to handle your data this way, manually copying and pasting different bits of data from different files.

这篇关于使用 read.table(text=“....") RStudio 加速在控制台中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆