我有很长一段时间。在以下示例中,仅包含前100行。 运行线后:
Lines <- "Hour,PF
1,26/11/2014 13:00, 0
2,26/11/2014 14:00,0.070
3,26/11/2014 15:00,0.070
4,26/11/2014 16:00,0.050
5,26/11/2014 17:00,0.060
6,26/11/2014 18:00,0.020
7,26/11/2014 19:00,0.040
8,26/11/2014 20:00,0.020
9,26/11/2014 21:00,0.020
10,26/11/2014 22:00,0.010
11,26/11/2014 23:00,0.020
12,27/11/2014 0:00,0.010
13,27/11/2014 1:00,0.010
14,27/11/2014 2:00,0.020
15,27/11/2014 3:00,0.010
16,27/11/2014 4:00,0.020
17,27/11/2014 5:00,0.010
18,27/11/2014 6:00,0.020
19,27/11/2014 7:00,0.010
20,27/11/2014 8:00,0.010
21,27/11/2014 9:00,0.060
22,27/11/2014 10:00,0.060
23,27/11/2014 11:00,0.060
24,27/11/2014 12:00,0.060
25,27/11/2014 13:00,0.080
26,27/11/2014 14:00,0.060
27,27/11/2014 15:00,0.060
28,27/11/2014 16:00,0.040
29,27/11/2014 17:00,0.060
30,27/11/2014 18:00,0.060
31,27/11/2014 19:00,0.020
32,27/11/2014 20:00,0.010
33,27/11/2014 21:00,0.020
34,27/11/2014 22:00,0.010
35,27/11/2014 23:00,0.010
36,28/11/2014 0:00,0.020
37,28/11/2014 1:00,0.010
38,28/11/2014 2:00,0.020
39,28/11/2014 3:00,0.010
40,28/11/2014 4:00,0.010
41,28/11/2014 5:00,0.020
42,28/11/2014 6:00,0.010
43,28/11/2014 7:00,0.020
44,28/11/2014 8:00,0.010
45,28/11/2014 9:00,0.010
46,28/11/2014 10:00,0.020
47,28/11/2014 11:00,0.010
48,28/11/2014 12:00,0.040
49,28/11/2014 13:00,0.060
50,28/11/2014 14:00,0.010
51,28/11/2014 15:00,0.010
52,28/11/2014 16:00,0.020
53,28/11/2014 17:00,0.010
54,28/11/2014 18:00,0.020
55,28/11/2014 19:00,0.010
56,28/11/2014 20:00,0.010
57,28/11/2014 21:00,0.020
58,28/11/2014 22:00,0.010
59,28/11/2014 23:00,0.020
60,29/11/2014 0:00,0.010
61,29/11/2014 1:00,0.010
62,29/11/2014 2:00,0.020
63,29/11/2014 3:00,0.010
64,29/11/2014 4:00,0.010
65,29/11/2014 5:00,0.020
66,29/11/2014 6:00,0.010
67,29/11/2014 7:00,0.020
68,29/11/2014 8:00,0.010
69,29/11/2014 9:00,0.010
70,29/11/2014 10:00,0.020
71,29/11/2014 11:00,0.010
72,29/11/2014 12:00,0.020
73,29/11/2014 13:00,0.010
74,29/11/2014 14:00,0.010
75,29/11/2014 15:00,0.020
76,29/11/2014 16:00,0.010
77,29/11/2014 17:00,0.020
78,29/11/2014 18:00,0.010
79,29/11/2014 19:00,0.010
80,29/11/2014 20:00,0.020
81,29/11/2014 21:00,0.010
82,29/11/2014 22:00,0.020
83,29/11/2014 23:00,0.010
84,30/11/2014 0:00,0.010
85,30/11/2014 1:00,0.020
86,30/11/2014 2:00,0.010
87,30/11/2014 3:00,0.020
88,30/11/2014 4:00,0.010
89,30/11/2014 5:00,0.010
90,30/11/2014 6:00,0.020
91,30/11/2014 7:00,0.010
92,30/11/2014 8:00,0.020
93,30/11/2014 9:00,0.020
94,30/11/2014 10:00,0.070
95,30/11/2014 11:00,0.060
96,30/11/2014 12:00,0.050
97,30/11/2014 13:00,0.060
98,30/11/2014 14:00,0.040
99,30/11/2014 15:00,0.050
100,30/11/2014 16:00,0.070"
我运行以下内容:
library (zoo)
library (strucchange)
z <- read.zoo(text = Lines, tz = "", format = "%d/%m/%Y %H:%M", sep = ",")
bp <- breakpoints(z ~ 1, h = 2)
breakpoints
的最后一个命令长时间停留。有没有办法用%dopar%
来解决它?
答案 0 :(得分:2)
#Load necessary libs
library('foreach')
library('doParallel')
#Register parallel backend
cl <- makeCluster(detectCores() - 1)
registerDoParallel(cl, cores = detectCores() - 1)
#Run breakpoints(), note usage of the `hpc` argument, see `?breakpoints`
bp <- breakpoints(z ~ 1, h=2, hpc='foreach')
#Deregister parallel backend
stopCluster(cl)