Gggplot line graph each day - r
I have this data frame below. I want to plot line graph using GGPLOT for each day of 'ind' column. In the 'ind'column I have the following dates repeated:
datedf<-as.Date(ux<-unique(df$ind))
> datedf
[1] "07/12/2015" "08.12.2015" "09.12.2015" "10.12.2015" "11.12.2015" "12.14.2015" "2015-12- 15 "" 12.16.2015 "[9]" 12/17/2015 "," 12/18/2015 "," 12/21/2015 "
I want to make a line graph that has as Y-axis 'estimatedRate' and 'Future' columns data together and as X-axis the 'm' column for each one of these days.
> mdf<-ux<-unique(df$m)
> mdf
[1] 21 42 63 84 105 126 147 168 189 210 231 252 273 294 315 336 357 378 399 420 441
[22] 462 483 504 525 546 567 588 609 630 651 672 693 714 735 756 777 798 819 840 861 882
[43] 903 924 945 966 987 1008 1029 1050 1071 1092 1113 1134 1155 1176 1197 1218 1239 1260 1281 1302 1323
[64] 1344 1365 1386 1407 1428 1449 1470 1491 1512 1533 1554 1575 1596 1617 1638 1659 1680 1701 1722 1743 1764
[85] 1785 1806 1827 1848 1869 1890 1911 1932 1953 1974 1995 2016 2037 2058 2079 2100 2121 2142 2163 2184 2205
[106] 2226 2247 2268 2289 2310 2331 2352 2373 2394 2415 2436 2457 2478 2499 2520
Notice that every 120 rows I have one day, and data related to this day in the columns 'estimatedRate' and 'Future'.
To make the first graph I use the first 120 lines, to make the second graph the second 120th lines and so on.
ind m estimatedRate Future
1 2015-12-07 21 0.1418127 0.1417730
2 2015-12-07 42 0.1420864 0.1427000
3 2015-12-07 63 0.1464147 0.1445127
4 2015-12-07 84 0.1494089 0.1463107
5 2015-12-07 105 0.1513357 0.1480558
6 2015-12-07 126 0.1526393 0.1499211
7 2015-12-07 147 0.1535730 0.1514676
8 2015-12-07 168 0.1542737 0.1531931
9 2015-12-07 189 0.1548187 0.1544670
10 2015-12-07 210 0.1552547 0.1555310
11 2015-12-07 231 0.1556115 0.1563341
12 2015-12-07 252 0.1559088 0.1569693
13 2015-12-07 273 0.1561603 0.1575226
14 2015-12-07 294 0.1563759 0.1581614
15 2015-12-07 315 0.1565628 0.1587338
16 2015-12-07 336 0.1567263 0.1591577
17 2015-12-07 357 0.1568706 0.1595782
18 2015-12-07 378 0.1569988 0.1599672
19 2015-12-07 399 0.1571136 0.1602606
20 2015-12-07 420 0.1572168 0.1603606
21 2015-12-07 441 0.1573103 0.1605000
22 2015-12-07 462 0.1573952 0.1606000
23 2015-12-07 483 0.1574728 0.1606000
24 2015-12-07 504 0.1575438 0.1606000
25 2015-12-07 525 0.1576092 0.1606000
26 2015-12-07 546 0.1576696 0.1606849
27 2015-12-07 567 0.1577255 0.1607000
28 2015-12-07 588 0.1577774 0.1607000
29 2015-12-07 609 0.1578258 0.1608000
30 2015-12-07 630 0.1578709 0.1608000
31 2015-12-07 651 0.1579131 0.1608000
32 2015-12-07 672 0.1579526 0.1608000
33 2015-12-07 693 0.1579898 0.1608000
34 2015-12-07 714 0.1580247 0.1607000
35 2015-12-07 735 0.1580577 0.1607000
36 2015-12-07 756 0.1580889 0.1607000
37 2015-12-07 777 0.1581183 0.1607000
38 2015-12-07 798 0.1581462 0.1606000
39 2015-12-07 819 0.1581727 0.1605000
40 2015-12-07 840 0.1581979 0.1604000
41 2015-12-07 861 0.1582218 0.1602935
42 2015-12-07 882 0.1582446 0.1602274
43 2015-12-07 903 0.1582663 0.1600911
44 2015-12-07 924 0.1582871 0.1600000
45 2015-12-07 945 0.1583069 0.1598089
46 2015-12-07 966 0.1583258 0.1596099
47 2015-12-07 987 0.1583440 0.1595128
48 2015-12-07 1008 0.1583614 0.1593824
49 2015-12-07 1029 0.1583781 0.1592110
50 2015-12-07 1050 0.1583941 0.1591128
51 2015-12-07 1071 0.1584095 0.1589000
52 2015-12-07 1092 0.1584243 0.1588000
53 2015-12-07 1113 0.1584385 0.1585936
54 2015-12-07 1134 0.1584522 0.1584613
55 2015-12-07 1155 0.1584654 0.1583922
56 2015-12-07 1176 0.1584782 0.1582099
57 2015-12-07 1197 0.1584905 0.1581000
58 2015-12-07 1218 0.1585023 0.1580000
59 2015-12-07 1239 0.1585138 0.1579000
60 2015-12-07 1260 0.1585249 0.1577715
61 2015-12-07 1281 0.1585356 0.1577000
62 2015-12-07 1302 0.1585460 0.1576000
63 2015-12-07 1323 0.1585560 0.1575767
64 2015-12-07 1344 0.1585658 0.1575000
65 2015-12-07 1365 0.1585752 0.1574936
66 2015-12-07 1386 0.1585844 0.1574277
67 2015-12-07 1407 0.1585932 0.1573908
68 2015-12-07 1428 0.1586018 0.1573000
69 2015-12-07 1449 0.1586102 0.1572916
70 2015-12-07 1470 0.1586183 0.1572000
71 2015-12-07 1491 0.1586262 0.1571940
72 2015-12-07 1512 0.1586339 0.1571319
73 2015-12-07 1533 0.1586414 0.1571000
74 2015-12-07 1554 0.1586486 0.1571000
75 2015-12-07 1575 0.1586557 0.1572000
76 2015-12-07 1596 0.1586626 0.1572000
77 2015-12-07 1617 0.1586693 0.1572093
78 2015-12-07 1638 0.1586758 0.1572731
79 2015-12-07 1659 0.1586822 0.1573000
80 2015-12-07 1680 0.1586884 0.1573000
81 2015-12-07 1701 0.1586945 0.1573000
82 2015-12-07 1722 0.1587004 0.1573101
83 2015-12-07 1743 0.1587061 0.1574000
84 2015-12-07 1764 0.1587118 0.1574000
85 2015-12-07 1785 0.1587173 0.1574000
86 2015-12-07 1806 0.1587226 0.1574000
87 2015-12-07 1827 0.1587279 0.1574000
88 2015-12-07 1848 0.1587330 0.1574000
89 2015-12-07 1869 0.1587380 0.1574000
90 2015-12-07 1890 0.1587429 0.1574000
91 2015-12-07 1911 0.1587477 0.1574000
92 2015-12-07 1932 0.1587524 0.1574092
93 2015-12-07 1953 0.1587570 0.1574731
94 2015-12-07 1974 0.1587615 0.1575000
95 2015-12-07 1995 0.1587659 0.1575000
96 2015-12-07 2016 0.1587702 0.1575000
97 2015-12-07 2037 0.1587744 0.1575000
98 2015-12-07 2058 0.1587785 0.1575000
99 2015-12-07 2079 0.1587825 0.1575000
100 2015-12-07 2100 0.1587865 0.1575000
101 2015-12-07 2121 0.1587904 0.1575000
102 2015-12-07 2142 0.1587942 0.1575000
103 2015-12-07 2163 0.1587979 0.1575000
104 2015-12-07 2184 0.1588016 0.1575000
105 2015-12-07 2205 0.1588052 0.1575000
106 2015-12-07 2226 0.1588087 0.1575000
107 2015-12-07 2247 0.1588122 0.1575000
108 2015-12-07 2268 0.1588156 0.1575000
109 2015-12-07 2289 0.1588189 0.1575000
110 2015-12-07 2310 0.1588222 0.1575018
111 2015-12-07 2331 0.1588254 0.1575385
112 2015-12-07 2352 0.1588286 0.1575746
113 2015-12-07 2373 0.1588317 0.1576190
114 2015-12-07 2394 0.1588347 0.1576846
115 2015-12-07 2415 0.1588377 0.1577000
116 2015-12-07 2436 0.1588406 0.1577000
117 2015-12-07 2457 0.1588435 0.1577000
118 2015-12-07 2478 0.1588464 0.1577131
119 2015-12-07 2499 0.1588492 0.1578000
120 2015-12-07 2520 0.1588519 0.1578000
121 2015-12-07 21 0.1418127 0.1417730
122 2015-12-07 42 0.1420864 0.1427000
123 2015-12-07 63 0.1464147 0.1445127
124 2015-12-07 84 0.1494089 0.1463107
125 2015-12-07 105 0.1513357 0.1480558
126 2015-12-07 126 0.1526393 0.1499211
127 2015-12-07 147 0.1535730 0.1514676
128 2015-12-07 168 0.1542737 0.1531931
129 2015-12-07 189 0.1548187 0.1544670
130 2015-12-07 210 0.1552547 0.1555310
131 2015-12-07 231 0.1556115 0.1563341
132 2015-12-07 252 0.1559088 0.1569693
133 2015-12-07 273 0.1561603 0.1575226
134 2015-12-07 294 0.1563759 0.1581614
135 2015-12-07 315 0.1565628 0.1587338
136 2015-12-07 336 0.1567263 0.1591577
137 2015-12-07 357 0.1568706 0.1595782
138 2015-12-07 378 0.1569988 0.1599672
139 2015-12-07 399 0.1571136 0.1602606
140 2015-12-07 420 0.1572168 0.1603606
141 2015-12-07 441 0.1573103 0.1605000
142 2015-12-07 462 0.1573952 0.1606000
143 2015-12-07 483 0.1574728 0.1606000
144 2015-12-07 504 0.1575438 0.1606000
145 2015-12-07 525 0.1576092 0.1606000
146 2015-12-07 546 0.1576696 0.1606849
147 2015-12-07 567 0.1577255 0.1607000
148 2015-12-07 588 0.1577774 0.1607000
149 2015-12-07 609 0.1578258 0.1608000
150 2015-12-07 630 0.1578709 0.1608000
151 2015-12-07 651 0.1579131 0.1608000
152 2015-12-07 672 0.1579526 0.1608000
153 2015-12-07 693 0.1579898 0.1608000
154 2015-12-07 714 0.1580247 0.1607000
155 2015-12-07 735 0.1580577 0.1607000
156 2015-12-07 756 0.1580889 0.1607000
157 2015-12-07 777 0.1581183 0.1607000
158 2015-12-07 798 0.1581462 0.1606000
159 2015-12-07 819 0.1581727 0.1605000
160 2015-12-07 840 0.1581979 0.1604000
161 2015-12-07 861 0.1582218 0.1602935
162 2015-12-07 882 0.1582446 0.1602274
163 2015-12-07 903 0.1582663 0.1600911
164 2015-12-07 924 0.1582871 0.1600000
165 2015-12-07 945 0.1583069 0.1598089
166 2015-12-07 966 0.1583258 0.1596099
167 2015-12-07 987 0.1583440 0.1595128
168 2015-12-07 1008 0.1583614 0.1593824
169 2015-12-07 1029 0.1583781 0.1592110
170 2015-12-07 1050 0.1583941 0.1591128
171 2015-12-07 1071 0.1584095 0.1589000
172 2015-12-07 1092 0.1584243 0.1588000
173 2015-12-07 1113 0.1584385 0.1585936
174 2015-12-07 1134 0.1584522 0.1584613
175 2015-12-07 1155 0.1584654 0.1583922
176 2015-12-07 1176 0.1584782 0.1582099
177 2015-12-07 1197 0.1584905 0.1581000
178 2015-12-07 1218 0.1585023 0.1580000
179 2015-12-07 1239 0.1585138 0.1579000
180 2015-12-07 1260 0.1585249 0.1577715
181 2015-12-07 1281 0.1585356 0.1577000
182 2015-12-07 1302 0.1585460 0.1576000
183 2015-12-07 1323 0.1585560 0.1575767
184 2015-12-07 1344 0.1585658 0.1575000
185 2015-12-07 1365 0.1585752 0.1574936
186 2015-12-07 1386 0.1585844 0.1574277
187 2015-12-07 1407 0.1585932 0.1573908
188 2015-12-07 1428 0.1586018 0.1573000
189 2015-12-07 1449 0.1586102 0.1572916
190 2015-12-07 1470 0.1586183 0.1572000
191 2015-12-07 1491 0.1586262 0.1571940
192 2015-12-07 1512 0.1586339 0.1571319
193 2015-12-07 1533 0.1586414 0.1571000
194 2015-12-07 1554 0.1586486 0.1571000
195 2015-12-07 1575 0.1586557 0.1572000
196 2015-12-07 1596 0.1586626 0.1572000
197 2015-12-07 1617 0.1586693 0.1572093
198 2015-12-07 1638 0.1586758 0.1572731
199 2015-12-07 1659 0.1586822 0.1573000
200 2015-12-07 1680 0.1586884 0.1573000
201 2015-12-07 1701 0.1586945 0.1573000
202 2015-12-07 1722 0.1587004 0.1573101
203 2015-12-07 1743 0.1587061 0.1574000
204 2015-12-07 1764 0.1587118 0.1574000
205 2015-12-07 1785 0.1587173 0.1574000
206 2015-12-07 1806 0.1587226 0.1574000
207 2015-12-07 1827 0.1587279 0.1574000
208 2015-12-07 1848 0.1587330 0.1574000
209 2015-12-07 1869 0.1587380 0.1574000
210 2015-12-07 1890 0.1587429 0.1574000
211 2015-12-07 1911 0.1587477 0.1574000
212 2015-12-07 1932 0.1587524 0.1574092
213 2015-12-07 1953 0.1587570 0.1574731
214 2015-12-07 1974 0.1587615 0.1575000
215 2015-12-07 1995 0.1587659 0.1575000
216 2015-12-07 2016 0.1587702 0.1575000
217 2015-12-07 2037 0.1587744 0.1575000
218 2015-12-07 2058 0.1587785 0.1575000
219 2015-12-07 2079 0.1587825 0.1575000
220 2015-12-07 2100 0.1587865 0.1575000
221 2015-12-07 2121 0.1587904 0.1575000
222 2015-12-07 2142 0.1587942 0.1575000
223 2015-12-07 2163 0.1587979 0.1575000
224 2015-12-07 2184 0.1588016 0.1575000
225 2015-12-07 2205 0.1588052 0.1575000
226 2015-12-07 2226 0.1588087 0.1575000
227 2015-12-07 2247 0.1588122 0.1575000
228 2015-12-07 2268 0.1588156 0.1575000
229 2015-12-07 2289 0.1588189 0.1575000
230 2015-12-07 2310 0.1588222 0.1575018
231 2015-12-07 2331 0.1588254 0.1575385
232 2015-12-07 2352 0.1588286 0.1575746
233 2015-12-07 2373 0.1588317 0.1576190
234 2015-12-07 2394 0.1588347 0.1576846
235 2015-12-07 2415 0.1588377 0.1577000
236 2015-12-07 2436 0.1588406 0.1577000
237 2015-12-07 2457 0.1588435 0.1577000
238 2015-12-07 2478 0.1588464 0.1577131
239 2015-12-07 2499 0.1588492 0.1578000
240 2015-12-07 2520 0.1588519 0.1578000
241 2015-12-07 21 0.1418127 0.1417730
242 2015-12-07 42 0.1420864 0.1427000
243 2015-12-07 63 0.1464147 0.1445127
244 2015-12-07 84 0.1494089 0.1463107
245 2015-12-07 105 0.1513357 0.1480558
246 2015-12-07 126 0.1526393 0.1499211
247 2015-12-07 147 0.1535730 0.1514676
248 2015-12-07 168 0.1542737 0.1531931
249 2015-12-07 189 0.1548187 0.1544670
250 2015-12-07 210 0.1552547 0.1555310
251 2015-12-07 231 0.1556115 0.1563341
252 2015-12-07 252 0.1559088 0.1569693
253 2015-12-07 273 0.1561603 0.1575226
254 2015-12-07 294 0.1563759 0.1581614
255 2015-12-07 315 0.1565628 0.1587338
256 2015-12-07 336 0.1567263 0.1591577
257 2015-12-07 357 0.1568706 0.1595782
258 2015-12-07 378 0.1569988 0.1599672
259 2015-12-07 399 0.1571136 0.1602606
260 2015-12-07 420 0.1572168 0.1603606
261 2015-12-07 441 0.1573103 0.1605000
262 2015-12-07 462 0.1573952 0.1606000
263 2015-12-07 483 0.1574728 0.1606000
264 2015-12-07 504 0.1575438 0.1606000
265 2015-12-07 525 0.1576092 0.1606000
266 2015-12-07 546 0.1576696 0.1606849
267 2015-12-07 567 0.1577255 0.1607000
268 2015-12-07 588 0.1577774 0.1607000
269 2015-12-07 609 0.1578258 0.1608000
270 2015-12-07 630 0.1578709 0.1608000
271 2015-12-07 651 0.1579131 0.1608000
272 2015-12-07 672 0.1579526 0.1608000
273 2015-12-07 693 0.1579898 0.1608000
274 2015-12-07 714 0.1580247 0.1607000
275 2015-12-07 735 0.1580577 0.1607000
276 2015-12-07 756 0.1580889 0.1607000
277 2015-12-07 777 0.1581183 0.1607000
278 2015-12-07 798 0.1581462 0.1606000
279 2015-12-07 819 0.1581727 0.1605000
280 2015-12-07 840 0.1581979 0.1604000
281 2015-12-07 861 0.1582218 0.1602935
282 2015-12-07 882 0.1582446 0.1602274
283 2015-12-07 903 0.1582663 0.1600911
284 2015-12-07 924 0.1582871 0.1600000
285 2015-12-07 945 0.1583069 0.1598089
286 2015-12-07 966 0.1583258 0.1596099
287 2015-12-07 987 0.1583440 0.1595128
288 2015-12-07 1008 0.1583614 0.1593824
289 2015-12-07 1029 0.1583781 0.1592110
290 2015-12-07 1050 0.1583941 0.1591128
291 2015-12-07 1071 0.1584095 0.1589000
292 2015-12-07 1092 0.1584243 0.1588000
293 2015-12-07 1113 0.1584385 0.1585936
294 2015-12-07 1134 0.1584522 0.1584613
295 2015-12-07 1155 0.1584654 0.1583922
296 2015-12-07 1176 0.1584782 0.1582099
297 2015-12-07 1197 0.1584905 0.1581000
298 2015-12-07 1218 0.1585023 0.1580000
299 2015-12-07 1239 0.1585138 0.1579000
300 2015-12-07 1260 0.1585249 0.1577715
301 2015-12-07 1281 0.1585356 0.1577000
302 2015-12-07 1302 0.1585460 0.1576000
303 2015-12-07 1323 0.1585560 0.1575767
304 2015-12-07 1344 0.1585658 0.1575000
305 2015-12-07 1365 0.1585752 0.1574936
306 2015-12-07 1386 0.1585844 0.1574277
307 2015-12-07 1407 0.1585932 0.1573908
308 2015-12-07 1428 0.1586018 0.1573000
309 2015-12-07 1449 0.1586102 0.1572916
310 2015-12-07 1470 0.1586183 0.1572000
311 2015-12-07 1491 0.1586262 0.1571940
312 2015-12-07 1512 0.1586339 0.1571319
313 2015-12-07 1533 0.1586414 0.1571000
314 2015-12-07 1554 0.1586486 0.1571000
315 2015-12-07 1575 0.1586557 0.1572000
316 2015-12-07 1596 0.1586626 0.1572000
317 2015-12-07 1617 0.1586693 0.1572093
318 2015-12-07 1638 0.1586758 0.1572731
319 2015-12-07 1659 0.1586822 0.1573000
320 2015-12-07 1680 0.1586884 0.1573000
321 2015-12-07 1701 0.1586945 0.1573000
322 2015-12-07 1722 0.1587004 0.1573101
323 2015-12-07 1743 0.1587061 0.1574000
324 2015-12-07 1764 0.1587118 0.1574000
325 2015-12-07 1785 0.1587173 0.1574000
326 2015-12-07 1806 0.1587226 0.1574000
327 2015-12-07 1827 0.1587279 0.1574000
328 2015-12-07 1848 0.1587330 0.1574000
329 2015-12-07 1869 0.1587380 0.1574000
330 2015-12-07 1890 0.1587429 0.1574000
331 2015-12-07 1911 0.1587477 0.1574000
332 2015-12-07 1932 0.1587524 0.1574092
333 2015-12-07 1953 0.1587570 0.1574731
334 2015-12-07 1974 0.1587615 0.1575000
335 2015-12-07 1995 0.1587659 0.1575000
336 2015-12-07 2016 0.1587702 0.1575000
337 2015-12-07 2037 0.1587744 0.1575000
338 2015-12-07 2058 0.1587785 0.1575000
339 2015-12-07 2079 0.1587825 0.1575000
340 2015-12-07 2100 0.1587865 0.1575000
341 2015-12-07 2121 0.1587904 0.1575000
342 2015-12-07 2142 0.1587942 0.1575000
343 2015-12-07 2163 0.1587979 0.1575000
344 2015-12-07 2184 0.1588016 0.1575000
345 2015-12-07 2205 0.1588052 0.1575000
346 2015-12-07 2226 0.1588087 0.1575000
347 2015-12-07 2247 0.1588122 0.1575000
348 2015-12-07 2268 0.1588156 0.1575000
349 2015-12-07 2289 0.1588189 0.1575000
350 2015-12-07 2310 0.1588222 0.1575018
351 2015-12-07 2331 0.1588254 0.1575385
352 2015-12-07 2352 0.1588286 0.1575746
353 2015-12-07 2373 0.1588317 0.1576190
354 2015-12-07 2394 0.1588347 0.1576846
355 2015-12-07 2415 0.1588377 0.1577000
356 2015-12-07 2436 0.1588406 0.1577000
357 2015-12-07 2457 0.1588435 0.1577000
358 2015-12-07 2478 0.1588464 0.1577131
359 2015-12-07 2499 0.1588492 0.1578000
360 2015-12-07 2520 0.1588519 0.1578000
361 2015-12-08 21 0.1418127 0.1419048
362 2015-12-08 42 0.1420864 0.1429000
363 2015-12-08 63 0.1464147 0.1446142
364 2015-12-08 84 0.1494089 0.1465071
365 2015-12-08 105 0.1513357 0.1483599
366 2015-12-08 126 0.1526393 0.1501925
367 2015-12-08 147 0.1535730 0.1517595
368 2015-12-08 168 0.1542737 0.1534194
369 2015-12-08 189 0.1548187 0.1547000
370 2015-12-08 210 0.1552547 0.1557739
371 2015-12-08 231 0.1556115 0.1566678
372 2015-12-08 252 0.1559088 0.1573265
373 2015-12-08 273 0.1561603 0.1579527
374 2015-12-08 294 0.1563759 0.1585816
375 2015-12-08 315 0.1565628 0.1590505
376 2015-12-08 336 0.1567263 0.1595437
377 2015-12-08 357 0.1568706 0.1598891
378 2015-12-08 378 0.1569988 0.1602782
379 2015-12-08 399 0.1571136 0.1605000
380 2015-12-08 420 0.1572168 0.1606000
381 2015-12-08 441 0.1573103 0.1607000
382 2015-12-08 462 0.1573952 0.1607000
383 2015-12-08 483 0.1574728 0.1607000
384 2015-12-08 504 0.1575438 0.1607000
385 2015-12-08 525 0.1576092 0.1607000
386 2015-12-08 546 0.1576696 0.1607918
387 2015-12-08 567 0.1577255 0.1608000
388 2015-12-08 588 0.1577774 0.1608000
389 2015-12-08 609 0.1578258 0.1609000
390 2015-12-08 630 0.1578709 0.1609000
391 2015-12-08 651 0.1579131 0.1609000
392 2015-12-08 672 0.1579526 0.1608000
393 2015-12-08 693 0.1579898 0.1608000
394 2015-12-08 714 0.1580247 0.1607000
395 2015-12-08 735 0.1580577 0.1607000
396 2015-12-08 756 0.1580889 0.1606267
397 2015-12-08 777 0.1581183 0.1606000
398 2015-12-08 798 0.1581462 0.1605051
399 2015-12-08 819 0.1581727 0.1604000
400 2015-12-08 840 0.1581979 0.1603816
401 2015-12-08 861 0.1582218 0.1602903
402 2015-12-08 882 0.1582446 0.1602243
403 2015-12-08 903 0.1582663 0.1600733
404 2015-12-08 924 0.1582871 0.1598907
405 2015-12-08 945 0.1583069 0.1597000
406 2015-12-08 966 0.1583258 0.1595000
407 2015-12-08 987 0.1583440 0.1593170
408 2015-12-08 1008 0.1583614 0.1591760
409 2015-12-08 1029 0.1583781 0.1590000
410 2015-12-08 1050 0.1583941 0.1589085
411 2015-12-08 1071 0.1584095 0.1587916
412 2015-12-08 1092 0.1584243 0.1585949
413 2015-12-08 1113 0.1584385 0.1584872
414 2015-12-08 1134 0.1584522 0.1583551
415 2015-12-08 1155 0.1584654 0.1582845
416 2015-12-08 1176 0.1584782 0.1582000
417 2015-12-08 1197 0.1584905 0.1580916
418 2015-12-08 1218 0.1585023 0.1579944
419 2015-12-08 1239 0.1585138 0.1578938
420 2015-12-08 1260 0.1585249 0.1577655
421 2015-12-08 1281 0.1585356 0.1577000
422 2015-12-08 1302 0.1585460 0.1577000
423 2015-12-08 1323 0.1585560 0.1576690
424 2015-12-08 1344 0.1585658 0.1576000
425 2015-12-08 1365 0.1585752 0.1576000
426 2015-12-08 1386 0.1585844 0.1576000
427 2015-12-08 1407 0.1585932 0.1576000
428 2015-12-08 1428 0.1586018 0.1575832
429 2015-12-08 1449 0.1586102 0.1575000
430 2015-12-08 1470 0.1586183 0.1575000
431 2015-12-08 1491 0.1586262 0.1575000
432 2015-12-08 1512 0.1586339 0.1575000
433 2015-12-08 1533 0.1586414 0.1575000
434 2015-12-08 1554 0.1586486 0.1574944
435 2015-12-08 1575 0.1586557 0.1574000
436 2015-12-08 1596 0.1586626 0.1574000
437 2015-12-08 1617 0.1586693 0.1574000
438 2015-12-08 1638 0.1586758 0.1574000
439 2015-12-08 1659 0.1586822 0.1574000
440 2015-12-08 1680 0.1586884 0.1574000
441 2015-12-08 1701 0.1586945 0.1573832
442 2015-12-08 1722 0.1587004 0.1573000
443 2015-12-08 1743 0.1587061 0.1573000
444 2015-12-08 1764 0.1587118 0.1573000
445 2015-12-08 1785 0.1587173 0.1573000
446 2015-12-08 1806 0.1587226 0.1573000
447 2015-12-08 1827 0.1587279 0.1573000
448 2015-12-08 1848 0.1587330 0.1572832
449 2015-12-08 1869 0.1587380 0.1572000
450 2015-12-08 1890 0.1587429 0.1572000
451 2015-12-08 1911 0.1587477 0.1572000
452 2015-12-08 1932 0.1587524 0.1572000
453 2015-12-08 1953 0.1587570 0.1572000
454 2015-12-08 1974 0.1587615 0.1572000
455 2015-12-08 1995 0.1587659 0.1571869
456 2015-12-08 2016 0.1587702 0.1571191
457 2015-12-08 2037 0.1587744 0.1571000
458 2015-12-08 2058 0.1587785 0.1571000
459 2015-12-08 2079 0.1587825 0.1571000
460 2015-12-08 2100 0.1587865 0.1571000
461 2015-12-08 2121 0.1587904 0.1571000
462 2015-12-08 2142 0.1587942 0.1571000
463 2015-12-08 2163 0.1587979 0.1570481
464 2015-12-08 2184 0.1588016 0.1570000
465 2015-12-08 2205 0.1588052 0.1570000
466 2015-12-08 2226 0.1588087 0.1570000
467 2015-12-08 2247 0.1588122 0.1570000
468 2015-12-08 2268 0.1588156 0.1570000
469 2015-12-08 2289 0.1588189 0.1570000
470 2015-12-08 2310 0.1588222 0.1570000
471 2015-12-08 2331 0.1588254 0.1570000
472 2015-12-08 2352 0.1588286 0.1570000
473 2015-12-08 2373 0.1588317 0.1570000
474 2015-12-08 2394 0.1588347 0.1570000
475 2015-12-08 2415 0.1588377 0.1570000
476 2015-12-08 2436 0.1588406 0.1570000
477 2015-12-08 2457 0.1588435 0.1570000
478 2015-12-08 2478 0.1588464 0.1570000
479 2015-12-08 2499 0.1588492 0.1570000
480 2015-12-08 2520 0.1588519 0.1570000
481 2015-12-09 21 0.1418127 0.1419000
482 2015-12-09 42 0.1420864 0.1429698
483 2015-12-09 63 0.1464147 0.1447095
484 2015-12-09 84 0.1494089 0.1464277
485 2015-12-09 105 0.1513357 0.1482057
...
22437 2015-12-21 2457 0.1660790 0.1639335
22438 2015-12-21 2478 0.1660834 0.1639000
22439 2015-12-21 2499 0.1660878 0.1638653
22440 2015-12-21 2520 0.1660921 0.1638000
...
I'm trying to make a 'for' or a function that gives me line graphs for EACH day. But this very complicated as im begginer in R.
What I got so far was plot the graph of the columns 'estimatedRate' and 'Future' together.
ggplot(data=df, aes(x=df$m, y=df$DiFuturo, colour=ind))+
xlab('VĂ©rtices') + ylab('Taxas')+
theme(legend.title=element_blank(), legend.position='top') +
ggtitle('Curvas de DI1')+
geom_point()+ geom_line()+
geom_point(aes(x=df$m,y = df$estimatedRate,colour=ind)) +
geom_point(y = df$estimatedRate, color="black")+
geom_line(y = df$estimatedRate, color="blue")+
theme(axis.text = element_text(size = 12,colour="black"),axis.text.x=element_text(angle = 45))
But I would like separated line graphs. In the end I would end up with 11 charts.
Could you give me a hint?
I am not sure if I understand correctly but I hope it will help.
I took a subset of your dataset
df <- structure(list(ind = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), .Label = "2015-12-07", class = "factor"), m = c(21L,
42L, 63L, 21L, 42L, 63L, 21L, 42L, 63L), estimatedRate = c(0.1418127,
0.1420864, 0.1464147, 0.1494089, 0.1513357, 0.1526393, 0.153573,
0.1542737, 0.1548187), Future = c(0.141773, 0.1427, 0.1445127,
0.1463107, 0.1480558, 0.1499211, 0.1514676, 0.1531931, 0.154467
), Blocks = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), class = "factor", .Label = c("A",
"B", "C"))), .Names = c("ind", "m", "estimatedRate", "Future",
"Blocks"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8",
"9"), class = "data.frame")
a create a new column for block
x <- factor(LETTERS[1:3]); names(x) <- letters[1:3]
df$Blocks <- rep(x, each=3)
df
and then plot
ggplot(data=df, aes(x=m, y=Future, colour=Blocks))+
xlab('VĂ©rtices') + ylab('Taxas')+
theme(legend.title=element_blank(), legend.position='top') +
ggtitle('Curvas de DI1')+
geom_point()+ geom_line()+
geom_point(aes(x=m, y = estimatedRate,colour=ind)) +
geom_point(y = df$estimatedRate, color="black")+
geom_line(y = df$estimatedRate, color="blue")+
theme(axis.text = element_text(size = 12,colour="black"),axis.text.x=element_text(angle = 45)) + facet_grid(Blocks~.)
it gives
Related
Calculating number combinations through R
I have following data. i want to first find out the most occurring digit on every place value. Obviously one place can have 10 possibilities from 0 to 9. Than i want an option where by i can choose 5 top occurrences or 6 or 7 or 8 top occurrences for e.g. if i choose 5 then the program should take the top 5 occurrences or if i choose 8 then program should leave out the least 2 occurring digits and take all others. Data example: 076060 693022 585821 980575 438068 766214 051726 060417 822591 015507 635576 180231 212238 417651 631269 720767 348344 532148 748085 474026 380897 512421 749492 423616 950330 930079 097759 638901 319356 683308 818127 880675 256095 639187 339904 945437 799571 466063 428853 397799 782034 462486 739342 879023 419264 793319 603131 315791 351701 151747 365656 982700 348093 793392 946875 912108 070001 780515 222468 345439 234846 227112 757243 341747 480781 906624 868265 388572 947873 898895 452518 738580 217342 849951 437382 247068 743776 562584 636948 049434 139296 688436 443629 I want option of choosing 5, 6,7 or 8 top occurrences and 2 or 3 or 4number combination Expected results, 2 number combination basis top 8 occurrences and so on. 01 02 03 04 05 06 08 09 21 22 23 24 25 26 28 29 31 32 33 34 35 36 38 39 41 42 43 44 45 46 48 49 61 62 63 64 65 66 68 69 71 72 73 74 75 76 78 79 81 82 83 84 85 86 88 89 91 92 93 94 95 96 98 99 Expected results, 3 number combination basis top 8 occurrences and so on. 010 012 013 015 016 017 018 019 020 022 023 025 026 027 028 029 030 032 033 035 036 037 038 039 040 042 043 045 046 047 048 049 050 052 053 055 056 057 058 059 060 062 063 065 066 067 068 069 080 082 083 085 086 087 088 089 090 092 093 095 096 097 098 099 210 212 213 215 216 217 218 219 220 222 223 225 226 227 228 229 230 232 233 235 236 237 238 239 240 242 243 245 246 247 248 249 250 252 253 255 256 257 258 259 260 262 263 265 266 267 268 269 280 282 283 285 286 287 288 289 290 292 293 295 296 297 298 299 310 312 313 315 316 317 318 319 320 322 323 325 326 327 328 329 330 332 333 335 336 337 338 339 340 342 343 345 346 347 348 349 350 352 353 355 356 357 358 359 360 362 363 365 366 367 368 369 380 382 383 385 386 387 388 389 390 392 393 395 396 397 398 399 410 412 413 415 416 417 418 419 420 422 423 425 426 427 428 429 430 432 433 435 436 437 438 439 440 442 443 445 446 447 448 449 450 452 453 455 456 457 458 459 460 462 463 465 466 467 468 469 480 482 483 485 486 487 488 489 490 492 493 495 496 497 498 499 610 612 613 615 616 617 618 619 620 622 623 625 626 627 628 629 630 632 633 635 636 637 638 639 640 642 643 645 646 647 648 649 650 652 653 655 656 657 658 659 660 662 663 665 666 667 668 669 680 682 683 685 686 687 688 689 690 692 693 695 696 697 698 699 710 712 713 715 716 717 718 719 720 722 723 725 726 727 728 729 730 732 733 735 736 737 738 739 740 742 743 745 746 747 748 749 750 752 753 755 756 757 758 759 760 762 763 765 766 767 768 769 780 782 783 785 786 787 788 789 790 792 793 795 796 797 798 799 810 812 813 815 816 817 818 819 820 822 823 825 826 827 828 829 830 832 833 835 836 837 838 839 840 842 843 845 846 847 848 849 850 852 853 855 856 857 858 859 860 862 863 865 866 867 868 869 880 882 883 885 886 887 888 889 890 892 893 895 896 897 898 899 910 912 913 915 916 917 918 919 920 922 923 925 926 927 928 929 930 932 933 935 936 937 938 939 940 942 943 945 946 947 948 949 950 952 953 955 956 957 958 959 960 962 963 965 966 967 968 969 980 982 983 985 986 987 988 989 990 992 993 995 996 997 998 999 code i have tried getwd() setwd("C:/Users/aziq/Desktop") library(xlsx) x <- read.xlsx("numbers.xlsx","Sheet1") generate_combinations <- function(x, pos, n) { #select first pos characters from each string #split each character and create a matrix mat <- do.call(rbind, strsplit(substr(x, 1, pos), '')) #Find top n occurrence in each column of matrix tmp <- apply(mat, 2, function(x) tail(names(sort(table(x))), n)) #Create all combinations of top occurrences. do.call(expand.grid, asplit(tmp, 2)) } generate_combinations(x, 2, 8) nrow(generate_combinations(x, 2, 8)) Error it is showing Error in asplit(tmp, 2) : dim(x) must have a positive length Dput results: > dput(x) structure(list(X076060 = c("693022", "585821", "980575", "438068", "766214", "051726", "060417", "822591", "015507", "635576", "180231", "212238", "417651", "631269", "720767", "348344", "532148", "748085", "474026", "380897", "512421", "749492", "423616", "950330", "930079", "097759", "638901", "319356", "683308", "818127", "880675", "256095", "639187", "339904", "945437", "799571", "466063", "428853", "397799", "782034", "462486", "739342", "879023", "419264", "793319", "603131", "315791", "351701", "151747", "365656", "982700", "348093", "793392", "946875", "912108", "070001", "780515", "222468", "345439", "234846", "227112", "757243", "341747", "480781", "906624", "868265", "388572", "947873", "898895", "452518", "738580", "217342", "849951", "437382", "247068", "743776", "562584", "636948", "049434", "139296", "688436", "443629")), class = "data.frame", row.names = c(NA, -82L))
We can write a function : generate_combinations <- function(x, pos, n) { if(pos == 1) { return(data.frame(Var1 = names(sort(table(substr(x, 1, pos)), = decreasing = TRUE)[1:n]))) } #select first pos characters from each string #split each character and create a matrix mat <- do.call(rbind, strsplit(substr(x, 1, pos), '')) #Find top n occurrence in each column of matrix tmp <- apply(mat, 2, function(x) tail(names(sort(table(x))), n)) #Create all combinations of top occurrences. do.call(expand.grid, asplit(tmp, 2)) } generate_combinations(x, 2, 8) # Var1 Var2 #1 0 2 #2 2 2 #3 8 2 #4 6 2 #5 9 2 #6 3 2 #7 4 2 #8 7 2 #9 0 5 #10 2 5 #... #... nrow(generate_combinations(x, 2, 8)) #[1] 64 nrow(generate_combinations(x, 3, 8)) #[1] 512 data x <- c("076060", "693022", "585821", "980575", "438068", "766214", "051726", "060417", "822591", "015507", "635576", "180231", "212238", "417651", "631269", "720767", "348344", "532148", "748085", "474026", "380897", "512421", "749492", "423616", "950330", "930079", "097759", "638901", "319356", "683308", "818127", "880675", "256095", "639187", "339904", "945437", "799571", "466063", "428853", "397799", "782034", "462486", "739342", "879023", "419264", "793319", "603131", "315791", "351701", "151747", "365656", "982700", "348093", "793392", "946875", "912108", "070001", "780515", "222468", "345439", "234846", "227112", "757243", "341747", "480781", "906624", "868265", "388572", "947873", "898895", "452518", "738580", "217342", "849951", "437382", "247068", "743776", "562584", "636948", "049434", "139296", "688436", "443629")
why is this butterworth filter presenting different results in R and Matlab?
I'm trying to use a 20Hz low pass filter on data in R, but when I use the filtfilt function, the plot is different from the matlab. I'm using the following code in R: fc<-20 fs<-100 Wn<-pi*fc/(2*fs) testar<- butter(5, Wn, type="low") L2<- signal::filtfilt(testar,Tabela$posicao) plot(Tabela$tempo, L2, type = "l", col="red") The matlab code is: fc=20; fs=100; Wn=pi*fc/(2*fs); [b,a] = butter(5,Wn,'low'); posfilt= filtfilt(b,a,Tabela.posicao); The plot in matlab is: The R one: why the R one is presenting those variation in the begin and in the end of the graph? Data can be produced as follows: Tabela <- data.table::fread(" tempo posicao 0 870.22 1 870.27 2 870.33 3 870.39 4 870.46 5 870.52 6 870.57 7 870.61 8 870.63 9 870.65 10 870.66 11 870.68 12 870.7 13 870.73 14 870.76 15 870.79 16 870.81 17 870.82 18 870.83 19 870.83 20 870.83 21 870.84 22 870.85 23 870.85 24 870.85 25 870.83 26 870.79 27 870.74 28 870.69 29 870.63 30 870.59 31 870.57 32 870.56 33 870.55 34 870.53 35 870.51 36 870.46 37 870.42 38 870.37 39 870.33 40 870.31 41 870.3 42 870.3 43 870.31 44 870.31 45 870.31 46 870.33 47 870.36 48 870.42 49 870.52 50 870.64 51 870.77 52 870.87 53 870.92 54 870.91 55 870.82 56 870.68 57 870.51 58 870.37 59 870.27 60 870.25 61 870.29 62 870.38 63 870.5 64 870.61 65 870.69 66 870.74 67 870.76 68 870.76 69 870.75 70 870.74 71 870.74 72 870.76 73 870.78 74 870.81 75 870.86 76 870.93 77 871.02 78 871.12 79 871.23 80 871.33 81 871.42 82 871.47 83 871.5 84 871.52 85 871.52 86 871.54 87 871.57 88 871.62 89 871.67 90 871.71 91 871.73 92 871.72 93 871.68 94 871.64 95 871.59 96 871.58 97 871.59 98 871.62 99 871.66 100 871.7 101 871.7 102 871.69 103 871.65 104 871.6 105 871.56 106 871.54 107 871.52 108 871.52 109 871.5 110 871.48 111 871.43 112 871.38 113 871.31 114 871.24 115 871.17 116 871.12 117 871.07 118 871.02 119 870.99 120 870.97 121 870.97 122 870.98 123 871.00 124 871.02 125 871.04 126 871.04 127 871.02 128 870.97 129 870.91 130 870.84 131 870.78 132 870.74 133 870.72 134 870.72 135 870.72 136 870.72 137 870.71 138 870.69 139 870.68 140 870.69 141 870.72 142 870.77 143 870.84 144 870.92 145 871.01 146 871.1 147 871.19 148 871.28 149 871.36 150 871.43 151 871.49 152 871.55 153 871.6 154 871.67 155 871.74 156 871.84 157 871.95 158 872.07 159 872.2 160 872.31 161 872.42 162 872.51 163 872.59 164 872.66 165 872.75 166 872.86 167 873.02 168 873.22 169 873.48 170 873.8 171 874.16 172 874.55 173 874.99 174 875.49 175 876.06 176 876.72 177 877.48 178 878.36 179 879.33 180 880.41 181 881.59 182 882.87 183 884.24 184 885.71 185 887.29 186 888.96 187 890.73 188 892.61 189 894.57 190 896.63 191 898.77 192 900.99 193 903.28 194 905.63 195 908.02 196 910.44 197 912.88 198 915.33 199 917.79 200 920.25 201 922.71 202 925.15 203 927.57 204 929.96 205 932.3 206 934.59 207 936.82 208 938.99 209 941.09 210 943.14 211 945.12 212 947.05 213 948.89 214 950.62 215 952.2 216 953.62 217 954.86 218 955.94 219 956.86 220 957.65 221 958.33 222 958.9 223 959.4 224 959.83 225 960.2 226 960.53 227 960.82 228 961.09 229 961.35 230 961.58 231 961.81 232 962.02 233 962.23 234 962.45 235 962.7 236 962.98 237 963.32 238 963.7 239 964.13 240 964.6 241 965.09 242 965.59 243 966.09 244 966.59 245 967.1 246 967.62 247 968.15 248 968.69 249 969.25 250 969.81 251 970.36 252 970.89 253 971.4 254 971.89 255 972.33 256 972.73 257 973.08 258 973.38 259 973.63 260 973.85 261 974.05 262 974.25 263 974.44 264 974.63 265 974.8 266 974.96 267 975.1 268 975.24 269 975.37 270 975.5 271 975.64 272 975.8 273 975.96 274 976.13 275 976.32 276 976.52 277 976.74 278 976.97 279 977.21 280 977.44 281 977.66 282 977.84 283 977.97 284 978.05 285 978.06 286 978.01 287 977.9 288 977.74 289 977.53 290 977.28 291 976.99 292 976.67 293 976.34 294 976.01 295 975.68 296 975.35 297 975.02 298 974.68 299 974.31 300 973.91 301 973.48 302 973.04 303 972.58 304 972.14 305 971.71 306 971.32 307 970.97 308 970.67 309 970.41 310 970.2 311 970.02 312 969.89 313 969.78 314 969.72 315 969.68 316 969.67 317 969.67 318 969.67 319 969.67 320 969.67 321 969.68 322 969.69 323 969.73 324 969.79 325 969.88 326 969.98 327 970.08 328 970.17 329 970.24 330 970.28 331 970.29 332 970.27 333 970.22 334 970.15 335 970.07 336 969.98 337 969.89 338 969.81 339 969.74 340 969.68 341 969.63 342 969.6 343 969.57 344 969.56 345 969.55 346 969.57 347 969.6 348 969.65 349 969.73 350 969.81 351 969.89 352 969.96 353 970.01 354 970.05 355 970.06 356 970.07 357 970.08 358 970.09 359 970.09 360 970.09 361 970.08 362 970.06 363 970.04 364 970.00 365 969.96 366 969.94 367 969.93 368 969.95 369 970.00 370 970.08 371 970.17 372 970.27 373 970.35 374 970.42 375 970.48 376 970.53 377 970.58 378 970.64 379 970.73 380 970.85 381 970.98 382 971.14 383 971.3 384 971.45 385 971.58 386 971.69 387 971.76 388 971.79 389 971.8 390 971.78 391 971.75 392 971.71 393 971.66 394 971.61 395 971.55 396 971.48 397 971.39 398 971.3 399 971.2 400 971.1 401 971.00 402 970.9 403 970.82 404 970.76 405 970.73 406 970.72 407 970.73 408 970.77 409 970.83 410 970.9 411 970.98 412 971.06 413 971.16 414 971.27 415 971.4 416 971.53 417 971.67 418 971.81 419 971.94 420 972.06 421 972.17 422 972.25 423 972.33 424 972.38 425 972.42 426 972.45 427 972.45 428 972.44 429 972.42 430 972.38 431 972.34 432 972.29 433 972.24 434 972.2 435 972.16 436 972.12 437 972.1 438 972.08 439 972.07 440 972.07 441 972.07 442 972.07 443 972.08 444 972.09 445 972.12 446 972.18 447 972.26 448 972.37 449 972.49 450 972.61 451 972.7 452 972.78 453 972.82 454 972.83 455 972.82 456 972.79 457 972.76 458 972.71 459 972.65 460 972.57 461 972.49 462 972.39 463 972.29 464 972.19 465 972.11 466 972.07 467 972.05 468 972.07 469 972.1 470 972.14 471 972.17 472 972.19 473 972.2 474 972.21 475 972.22 476 972.25 477 972.29 478 972.36 479 972.44 480 972.52 481 972.61 482 972.68 483 972.74 484 972.78 485 972.81 486 972.83 487 972.85 488 972.86 489 972.88 490 972.9 491 972.92 492 972.95 493 972.97 494 972.99 495 973.00 496 972.99 497 972.97 498 972.93 499 972.88 500 972.83 501 972.78 502 972.73 503 972.69 504 972.66 505 972.64 506 972.64 507 972.66 508 972.7 509 972.76 510 972.83 511 972.92 512 973.02 513 973.13 514 973.25 515 973.39 516 973.56 517 973.74 518 973.94 519 974.14 520 974.34 521 974.52 522 974.68 523 974.82 524 974.94 525 975.06 526 975.18 527 975.3 528 975.43 529 975.58 530 975.73 531 975.88 532 976.02 533 976.15 534 976.27 535 976.4 536 976.53 537 976.67 538 976.82 539 976.99 540 977.17 541 977.35 542 977.53 543 977.71 544 977.88 545 978.03 546 978.18 547 978.31 548 978.44 549 978.55 550 978.63 551 978.69 552 978.72 553 978.73 554 978.73 555 978.72 556 978.71 557 978.69 558 978.67 559 978.62 560 978.54 561 978.41 562 978.22 563 977.96 564 977.62 565 977.19 566 976.67 567 976.05 568 975.32 569 974.47 570 973.48 571 972.34 572 971.03 573 969.52 574 967.79 575 965.83 576 963.64 577 961.2 578 958.52 579 955.62 580 952.5 581 949.16 582 945.6 583 941.83 584 937.85 585 933.68 586 929.33 587 924.8 588 920.12 589 915.3 590 910.35 591 905.29 592 900.13 593 894.88 594 889.56 595 884.18 596 878.76 597 873.31 598 867.84 599 862.37 600 856.93 601 851.52 602 846.16 603 840.86 604 835.64 605 830.48 606 825.41 607 820.4 608 815.46 609 810.57 610 805.74 611 800.96 612 796.25 613 791.59 614 786.99 615 782.46 616 777.99 617 773.57 618 769.2 619 764.89 620 760.64 621 756.45 622 752.32 623 748.25 624 744.24 625 740.31 626 736.46 627 732.69 628 729.03 629 725.5 630 722.1 631 718.83 632 715.7 633 712.68 634 709.77 635 706.96 636 704.25 637 701.63 638 699.13 639 696.75 640 694.49 641 692.36 642 690.34 643 688.42 644 686.6 645 684.85 646 683.17 647 681.56 648 680.01 649 678.52 650 677.1 651 675.75 652 674.49 653 673.3 654 672.19 655 671.15 656 670.16 657 669.22 658 668.33 659 667.5 660 666.74 661 666.05 662 665.42 663 664.85 664 664.32 665 663.82 666 663.35 667 662.93 668 662.57 669 662.27 670 662.05 671 661.89 672 661.77 673 661.69 674 661.62 675 661.56 676 661.5 677 661.44 678 661.38 679 661.34 680 661.29 681 661.25 682 661.2 683 661.13 684 661.05 685 660.95 686 660.83 687 660.7 688 660.57 689 660.43 690 660.28 691 660.13 692 659.96 693 659.78 694 659.6 695 659.43 696 659.29 697 659.2 698 659.16 699 659.19 700 659.28 701 659.43 702 659.65 703 659.96 704 660.37 705 660.9 706 661.54 707 662.31 708 663.19 709 664.2 710 665.33 711 666.58 712 667.94 713 669.43 714 671.02 715 672.73 716 674.55 717 676.46 718 678.46 719 680.55 720 682.73 721 685.00 722 687.36 723 689.81 724 692.34 725 694.92 726 697.54 727 700.15 728 702.73 729 705.28 730 707.79 731 710.27 732 712.76 733 715.26 734 717.8 735 720.38 736 722.98 737 725.6 738 728.21 739 730.81 740 733.39 741 735.96 742 738.5 743 741.02 744 743.52 745 746.00 746 748.45 747 750.87 748 753.25 749 755.58 750 757.87 751 760.12 752 762.34 753 764.53 754 766.71 755 768.86 756 770.99 757 773.09 758 775.16 759 777.2 760 779.23 761 781.24 762 783.25 763 785.26 764 787.28 765 789.3 766 791.31 767 793.33 768 795.34 769 797.35 770 799.35 771 801.34 772 803.33 773 805.31 774 807.29 775 809.26 776 811.21 777 813.16 778 815.09 779 817.03 780 818.96 781 820.91 782 822.88 783 824.85 784 826.82 785 828.78 786 830.73 787 832.67 788 834.59 789 836.5 790 838.41 791 840.33 792 842.27 793 844.23 794 846.2 795 848.18 796 850.15 797 852.1 798 854.02 799 855.93 800 857.84 801 859.76 802 861.71 803 863.69 804 865.69 805 867.72 806 869.75 807 871.79 808 873.83 809 875.88 810 877.94 811 880.02 812 882.12 813 884.25 814 886.41 815 888.59 816 890.78 817 892.97 818 895.18 819 897.39 820 899.61 821 901.85 822 904.11 823 906.38 824 908.67 825 910.97 826 913.29 827 915.61 828 917.94 829 920.28 830 922.63 831 925.00 832 927.38 833 929.79 834 932.22 835 934.68 836 937.17 837 939.67 838 942.17 839 944.67 840 947.15 841 949.62 842 952.08 843 954.51 844 956.94 845 959.36 846 961.75 847 964.12 848 966.45 849 968.73 850 970.94 851 973.07 852 975.12 853 977.08 854 978.94 855 980.7 856 982.34 857 983.86 858 985.26 859 986.52 860 987.65 861 988.64 862 989.49 863 990.2 864 990.76 865 991.16 866 991.42 867 991.52 868 991.48 869 991.3 870 991.01 871 990.63 872 990.18 873 989.67 874 989.13 875 988.56 876 987.98 877 987.39 878 986.79 879 986.2 880 985.61 881 985.04 882 984.52 883 984.05 884 983.65 885 983.32 886 983.07 887 982.88 888 982.74 889 982.64 890 982.55 891 982.47 892 982.38 893 982.28 894 982.15 895 981.98 896 981.78 897 981.54 898 981.26 899 980.94 900 980.61 901 980.28 902 979.94 903 979.61 904 979.29 905 978.98 906 978.68 907 978.39 908 978.11 909 977.85 910 977.6 911 977.37 912 977.16 913 976.94 914 976.72 915 976.5 916 976.27 917 976.06 918 975.85 919 975.67 920 975.5 921 975.36 922 975.22 923 975.08 924 974.93 925 974.76 926 974.57 927 974.35 928 974.1 929 973.85 930 973.6 931 973.36 932 973.13 933 972.93 934 972.74 935 972.55 936 972.37 937 972.19 938 972.00 939 971.8 940 971.6 941 971.39 942 971.18 943 970.97 944 970.76 945 970.56 946 970.37 947 970.19 948 970.02 949 969.86 950 969.72 951 969.6 952 969.5 953 969.42 954 969.36 955 969.33 956 969.29 957 969.27 958 969.23 959 969.19 960 969.14 961 969.09 962 969.04 963 968.99 964 968.94 965 968.88 966 968.82 967 968.74 968 968.64 969 968.54 970 968.42 971 968.3 972 968.19 973 968.08 974 967.98 975 967.86 976 967.74 977 967.59 978 967.42 979 967.24 980 967.04 981 966.85 982 966.67 983 966.5 984 966.35 985 966.2 986 966.06 987 965.92 988 965.77 989 965.61 990 965.44 991 965.25 992 965.05 993 964.82 994 964.58 995 964.32 996 964.05 997 963.78 998 963.52 999 963.28 1000 963.06 1001 962.85 1002 962.65 1003 962.44 1004 962.18 1005 961.87 1006 961.49 1007 961.03 1008 960.49 1009 959.91 1010 959.32 1011 958.75 1012 958.23 1013 957.77 1014 957.33 1015 956.9 1016 956.43 1017 955.87 1018 955.19 1019 954.37 1020 953.43 1021 952.39 1022 951.28 1023 950.13 1024 948.96 1025 947.74 1026 946.48 1027 945.15 1028 943.74 1029 942.26 1030 940.72 1031 939.11 1032 937.45 1033 935.74 1034 933.95 1035 932.07 1036 930.11 1037 928.06 1038 925.97 1039 923.92 1040 921.98 1041 920.24 1042 918.75 1043 917.51 1044 916.51 1045 915.7 1046 915.04 1047 914.51 1048 914.1 1049 913.76 1050 913.44 1051 913.05 1052 912.52 1053 911.79 1054 910.86 1055 909.74 1056 908.49 1057 907.19 1058 905.91 1059 904.73 1060 903.71 1061 902.89 1062 902.28 1063 901.88 1064 901.66 1065 901.59 1066 901.65 1067 901.81 1068 902.03 1069 902.3 1070 902.56 1071 902.79 1072 902.96 1073 903.06 1074 903.09 1075 903.06 1076 902.97 1077 902.85 1078 902.7 1079 902.53 1080 902.36 1081 902.21 1082 902.07 1083 901.95 1084 901.83 1085 901.67 1086 901.46 1087 901.17 1088 900.77 1089 900.26 1090 899.61 1091 898.81 1092 897.85 1093 896.73 1094 895.47 1095 894.12 1096 892.74 1097 891.4 1098 890.16 1099 889.04 1100 888.02 1101 887.1 1102 886.26 1103 885.5 1104 884.81 1105 884.15 1106 883.45 1107 882.61 1108 881.56 1109 880.29 1110 878.88 1111 877.44 1112 876.11 1113 875.01 1114 874.2 1115 873.65 1116 873.28 1117 872.99 1118 872.69 1119 872.36 1120 872.02 1121 871.74 1122 871.56 1123 871.5 1124 871.53 1125 871.6 1126 871.62 1127 871.58 1128 871.45 1129 871.26 1130 871.06 1131 870.9 1132 870.81 1133 870.82 1134 870.92 1135 871.06 1136 871.21 1137 871.32 1138 871.36 1139 871.33 1140 871.24 1141 871.14 1142 871.08 1143 871.08 1144 871.15 1145 871.28 1146 871.43 1147 871.56 1148 871.62 1149 871.6 1150 871.51 1151 871.37 1152 871.2 1153 871.04 1154 870.89 1155 870.77 1156 870.66 1157 870.55 1158 870.44 1159 870.32 1160 870.22 1161 870.13 1162 870.08 1163 870.06 1164 870.07 1165 870.09 1166 870.12 1167 870.14 1168 870.13 1169 870.11 1170 870.08 1171 870.05 1172 870.03 1173 870.03 1174 870.04 1175 870.04 1176 870.03 1177 869.99 1178 869.93 1179 869.87 1180 869.83 1181 869.81 1182 869.83 1183 869.88 1184 869.94 1185 870.00 1186 870.03 1187 870.03 1188 870.02 1189 870.00 1190 870.00 1191 870.00 1192 870.03 1193 870.06 1194 870.1 1195 870.14 1196 870.17 1197 870.2 1198 870.24 1199 870.28 1200 870.33 1201 870.37 1202 870.39 1203 870.39 1204 870.36 1205 870.31 1206 870.24 1207 870.18 1208 870.13 1209 870.09 1210 870.05 1211 870.01 1212 869.95 1213 869.88 1214 869.81 1215 869.75 1216 869.72 1217 869.73 1218 869.77 1219 869.85 1220 869.93 1221 870.01 1222 870.06 1223 870.1 1224 870.11 1225 870.11 1226 870.11 1227 870.11 1228 870.11 1229 870.12 1230 870.14 1231 870.16")
I have hunch that the difference is in how each version handles end-effect transients. Your signal has a large DC-offset (~875). If you think of the signal as being zero 0 before and after the recording. The jump at the start of the signal gets processed by the filter and is seen as an artifact or end-effect. These end-effects are what you see in the R version of the filtered signal. From the R documentation from filtfilt this version is old and likely doesn't minimize the end transients (R 'filtfilt' docs). On the other hand the MATLAB version of filtfilt does; Quoting from the MATLAB documentation: "filtfilt minimizes start-up and ending transients by matching initial conditions. Do not use 'filtfilt' with differentiator and Hilbert FIR filters, because the operation of these filters depends heavily on their phase response." FILTFILT Documentation
As mentioned by Azim, the default implementation of signal::filtfilt() does not include any steps to remove end-effect transients. However, a very simple function that pads the series with a reversed values before/after and then subsets the result to the original range of interest can solve this problem. EndEffect <- function(filt,x) { signal::filtfilt(filt,c(rev(x),x,rev(x)))[(length(x) + 1):(2 * length(x))] } L2<- EndEffect(testar,Tabela$posicao) plot(Tabela$tempo, L2, type = "l", col="red")
Model fitting: From "nlmer" to "nlme"
How can I fit the following model BUT using "nlme" instead "nlmer"? The data (at the end of the post, you can find the data to reproduce the code written here). dd.gr <- groupedData(y ~ x | id, dd) Define some functions beta.model <- function(cl, b0, b1, b2) { f <- b0*(cl^b1)*(1-cl)^b2 return(f)} nform <- ~ b0*(cl^b1)*(1-cl)^b2 nfun <- deriv(nform, namevec=c("b0", "b1", "b2"), function.arg=c("cl","b0", "b1", "b2")) Generate start parameters start.dd <- nls(y ~ beta.model(x, b0, b1, b2), start=list(b0=1, b1=1, b2=1), data=dd.gr) start.dd <- coef(start.dd) Fit the nonlinear model fit <- lme4::nlmer(y ~ nfun(x, b0, b1, b2) ~ (b0|id), data = dd.gr, start = start.dd, REML=T) summary(fit) Nonlinear mixed model fit by maximum likelihood ['nlmerMod'] Formula: y ~ nfun(x, b0, b1, b2) ~ (b0 | id) Data: dd.gr AIC BIC logLik deviance df.resid -1673.5 -1652.0 841.7 -1683.5 534 Scaled residuals: Min 1Q Median 3Q Max -3.4812 -0.6319 0.0865 0.5712 3.2816 Random effects: Groups Name Variance Std.Dev. id b0 0.03537 0.18808 Residual 0.00221 0.04701 Number of obs: 539, groups: id, 20 Fixed effects: Estimate Std. Error t value b0 0.99075 0.04902 20.21 b1 0.45828 0.01449 31.62 b2 0.65220 0.01734 37.60 Correlation of Fixed Effects: b0 b1 b1 0.480 b2 0.475 0.809 I would be grateful if anyone could help me adapt my code for what I propose. Here the data "dd": y x id 1 0.19012041 0.033511 20 2 0.28284850 0.068081 20 3 0.30852905 0.101623 20 4 0.33527818 0.137577 20 5 0.38641197 0.170015 20 6 0.41929523 0.207414 20 7 0.41697570 0.240817 20 8 0.41720256 0.274229 20 9 0.42971583 0.311311 20 10 0.41991537 0.345469 20 11 0.43032094 0.377397 20 12 0.43643438 0.414996 20 13 0.42266673 0.446316 20 14 0.43037591 0.480386 20 15 0.41315721 0.516730 20 16 0.40941867 0.550281 20 17 0.38272123 0.586440 20 18 0.38690141 0.619709 20 19 0.37053631 0.655532 20 20 0.35475040 0.690939 20 21 0.33294172 0.722318 20 22 0.26763630 0.754480 20 23 0.21367107 0.793380 20 24 0.19283832 0.826003 20 25 0.18314927 0.862719 20 26 0.16607962 0.895078 20 27 0.10271515 0.929464 20 28 0.05054509 0.964828 20 29 0.12439211 0.055681 29 30 0.24075680 0.113468 29 31 0.28940082 0.165547 29 32 0.36451986 0.222673 29 33 0.39986469 0.279548 29 34 0.41949874 0.338177 29 35 0.42081401 0.387903 29 36 0.41949874 0.446316 29 37 0.41166800 0.500000 29 38 0.39383040 0.556794 29 39 0.35305355 0.613815 29 40 0.31752589 0.670729 29 41 0.28620056 0.722318 29 42 0.24354607 0.779668 29 43 0.21800329 0.837162 29 44 0.18740906 0.888411 29 45 0.16769700 0.946148 29 46 0.35212840 0.040750 1970 47 0.48320028 0.085903 1970 48 0.53451401 0.126127 1970 49 0.55424578 0.165547 1970 50 0.56271842 0.207414 1970 51 0.57498323 0.252096 1970 52 0.57982842 0.291917 1970 53 0.57911318 0.331517 1970 54 0.54955214 0.370496 1970 55 0.54106483 0.414996 1970 56 0.51983827 0.459525 1970 57 0.48683208 0.505156 1970 58 0.41197552 0.543154 1970 59 0.39301102 0.581372 1970 60 0.35144113 0.624610 1970 61 0.32615887 0.670729 1970 62 0.30356154 0.709662 1970 63 0.25400500 0.749612 1970 64 0.23843431 0.788056 1970 65 0.17314649 0.832348 1970 66 0.11181707 0.876633 1970 67 0.09217675 0.914606 1970 68 0.05513091 0.955580 1970 69 0.27973694 0.033511 1971 70 0.31497877 0.068081 1971 71 0.31774541 0.101623 1971 72 0.33633484 0.137577 1971 73 0.38142103 0.170015 1971 74 0.39212430 0.207414 1971 75 0.41776918 0.240817 1971 76 0.46544395 0.274229 1971 77 0.48094132 0.311311 1971 78 0.47609669 0.345469 1971 79 0.48437211 0.377397 1971 80 0.49303656 0.414996 1971 81 0.51532308 0.446316 1971 82 0.52591006 0.480386 1971 83 0.53168086 0.516730 1971 84 0.53575850 0.550281 1971 85 0.53642039 0.586440 1971 86 0.53831331 0.619709 1971 87 0.49989785 0.655532 1971 88 0.47896984 0.690939 1971 89 0.44155355 0.722318 1971 90 0.39668264 0.754480 1971 91 0.36687930 0.793380 1971 92 0.28175916 0.826003 1971 93 0.25477636 0.862719 1971 94 0.20772056 0.895078 1971 95 0.18146242 0.929464 1971 96 0.11509623 0.964828 1971 97 0.29424805 0.028771 2037 98 0.31100689 0.055681 2037 99 0.37968128 0.080921 2037 100 0.44570510 0.113468 2037 101 0.47689253 0.132828 2037 102 0.51388355 0.165547 2037 103 0.52951039 0.190470 2037 104 0.53486242 0.214077 2037 105 0.55310811 0.249102 2037 106 0.54069923 0.274229 2037 107 0.56085704 0.298996 2037 108 0.57346329 0.331517 2037 109 0.57252492 0.349985 2037 110 0.55666983 0.377397 2037 111 0.55588612 0.408420 2037 112 0.53516121 0.434682 2037 113 0.53464502 0.459525 2037 114 0.51990000 0.497546 2037 115 0.51118999 0.505156 2037 116 0.50976662 0.543154 2037 117 0.51704108 0.567886 2037 118 0.51518273 0.592719 2037 119 0.51144578 0.624610 2037 120 0.48702363 0.651879 2037 121 0.46874780 0.670729 2037 122 0.46610520 0.702626 2037 123 0.45957450 0.729257 2037 124 0.44940666 0.754480 2037 125 0.41248172 0.788056 2037 126 0.39988825 0.811593 2037 127 0.38568122 0.837162 2037 128 0.34338463 0.862719 2037 129 0.28846227 0.888411 2037 130 0.18329780 0.921480 2037 131 0.14774007 0.946148 2037 132 0.08575088 0.972091 2037 133 0.21763661 0.028771 2038 134 0.23256787 0.062335 2038 135 0.31054960 0.094141 2038 136 0.33781744 0.126127 2038 137 0.33712660 0.159287 2038 138 0.35776009 0.190470 2038 139 0.36132643 0.222673 2038 140 0.37726677 0.249102 2038 141 0.38080348 0.279548 2038 142 0.38177161 0.311311 2038 143 0.36956664 0.338177 2038 144 0.36977686 0.377397 2038 145 0.37166348 0.408420 2038 146 0.37411226 0.434682 2038 147 0.36272173 0.470750 2038 148 0.35090634 0.500000 2038 149 0.34812706 0.530893 2038 150 0.33913760 0.561354 2038 151 0.33184098 0.592719 2038 152 0.31086225 0.624610 2038 153 0.30179281 0.655532 2038 154 0.29244225 0.685227 2038 155 0.29171056 0.715608 2038 156 0.28896703 0.749612 2038 157 0.27356355 0.779668 2038 158 0.24517447 0.811593 2038 159 0.24808910 0.843440 2038 160 0.24206431 0.876633 2038 161 0.17025486 0.907147 2038 162 0.08859430 0.939046 2038 163 0.01079669 0.967649 2038 164 0.17164772 0.055681 2167 165 0.20956873 0.118653 2167 166 0.25329354 0.176730 2167 167 0.31110630 0.234884 2167 168 0.34389648 0.291917 2167 169 0.36050986 0.349985 2167 170 0.35936234 0.414996 2167 171 0.36918899 0.470750 2167 172 0.35897902 0.530893 2167 173 0.36581733 0.586440 2167 174 0.36862919 0.646015 2167 175 0.33702190 0.709662 2167 176 0.31287146 0.761244 2167 177 0.24696364 0.826003 2167 178 0.23022979 0.883711 2167 179 0.21250447 0.939046 2167 180 0.17598238 0.033511 2170 181 0.18737701 0.062335 2170 182 0.25275592 0.094141 2170 183 0.28559558 0.126127 2170 184 0.32734108 0.159287 2170 185 0.34818007 0.197259 2170 186 0.36637420 0.222673 2170 187 0.37547146 0.259716 2170 188 0.37475402 0.291917 2170 189 0.38964924 0.322916 2170 190 0.41576375 0.355376 2170 191 0.42667442 0.387903 2170 192 0.44626303 0.421442 2170 193 0.45753246 0.452095 2170 194 0.47906100 0.484540 2170 195 0.48635176 0.516730 2170 196 0.48690479 0.550281 2170 197 0.47611344 0.581372 2170 198 0.46409143 0.613815 2170 199 0.44356431 0.646015 2170 200 0.43274461 0.678666 2170 201 0.42292197 0.709662 2170 202 0.37036428 0.741452 2170 203 0.34960413 0.773048 2170 204 0.32294790 0.805637 2170 205 0.26755673 0.837162 2170 206 0.24912608 0.868745 2170 207 0.19643837 0.901224 2170 208 0.16754568 0.934460 2170 209 0.16021908 0.967649 2170 210 0.02224721 0.028771 2779 211 0.11104242 0.046814 2779 212 0.16841056 0.074093 2779 213 0.18409920 0.094141 2779 214 0.19098377 0.118653 2779 215 0.19968678 0.143437 2779 216 0.24379425 0.165547 2779 217 0.26619965 0.184325 2779 218 0.29353416 0.214077 2779 219 0.31359542 0.234884 2779 220 0.30777733 0.252096 2779 221 0.33962059 0.279548 2779 222 0.34543186 0.306186 2779 223 0.35301113 0.331517 2779 224 0.36405476 0.349985 2779 225 0.37258480 0.370496 2779 226 0.38418643 0.395798 2779 227 0.39501225 0.414996 2779 228 0.40087943 0.446316 2779 229 0.40893103 0.465443 2779 230 0.38764362 0.497546 2779 231 0.37029641 0.505156 2779 232 0.36884072 0.537179 2779 233 0.35422820 0.556794 2779 234 0.34543186 0.581372 2779 235 0.32837782 0.606240 2779 236 0.33608560 0.632230 2779 237 0.33095619 0.651879 2779 238 0.31397261 0.670729 2779 239 0.31170265 0.697418 2779 240 0.28869241 0.722318 2779 241 0.27357500 0.749612 2779 242 0.25919586 0.767440 2779 243 0.24564087 0.788056 2779 244 0.21054514 0.818738 2779 245 0.18037964 0.837162 2779 246 0.15573046 0.857893 2779 247 0.14260262 0.883711 2779 248 0.09563263 0.907147 2779 249 0.08206988 0.929464 2779 250 0.03908776 0.955580 2779 251 0.02125794 0.972091 2779 252 0.33096335 0.037328 2780 253 0.36969011 0.074093 2780 254 0.44504021 0.113468 2780 255 0.45485124 0.151987 2780 256 0.46464513 0.190470 2780 257 0.53736638 0.229281 2780 258 0.57555094 0.267528 2780 259 0.59723195 0.306186 2780 260 0.61552894 0.345469 2780 261 0.62033914 0.383389 2780 262 0.61015052 0.421442 2780 263 0.59728123 0.459525 2780 264 0.59515874 0.497546 2780 265 0.55152852 0.537179 2780 266 0.52641099 0.574251 2780 267 0.48956528 0.613815 2780 268 0.48497512 0.651879 2780 269 0.45698140 0.690939 2780 270 0.43844469 0.729257 2780 271 0.41683569 0.767440 2780 272 0.40151589 0.805637 2780 273 0.39202175 0.843440 2780 274 0.38459441 0.883711 2780 275 0.28157268 0.921480 2780 276 0.21164063 0.960888 2780 277 0.08489932 0.028771 1771 278 0.12305442 0.055681 1771 279 0.14546015 0.080921 1771 280 0.20507495 0.106794 1771 281 0.21327282 0.132828 1771 282 0.22885254 0.165547 1771 283 0.25315275 0.190470 1771 284 0.28460782 0.214077 1771 285 0.28404561 0.249102 1771 286 0.29963138 0.274229 1771 287 0.30334288 0.298996 1771 288 0.32026109 0.331517 1771 289 0.37167406 0.349985 1771 290 0.39620088 0.377397 1771 291 0.41163531 0.408420 1771 292 0.41672284 0.434682 1771 293 0.43135634 0.459525 1771 294 0.43591399 0.497546 1771 295 0.44049046 0.505156 1771 296 0.43976407 0.543154 1771 297 0.42582959 0.567886 1771 298 0.41946869 0.592719 1771 299 0.40894347 0.624610 1771 300 0.40408173 0.651879 1771 301 0.39886942 0.670729 1771 302 0.36607992 0.702626 1771 303 0.35079531 0.729257 1771 304 0.33792425 0.754480 1771 305 0.31231247 0.788056 1771 306 0.29062044 0.811593 1771 307 0.27997472 0.837162 1771 308 0.23381520 0.868745 1771 309 0.20789011 0.888411 1771 310 0.20415166 0.921480 1771 311 0.10956034 0.946148 1771 312 0.07090901 0.972091 1771 313 0.25314656 0.046814 1773 314 0.30329515 0.085903 1773 315 0.32123976 0.132828 1773 316 0.34022917 0.176730 1773 317 0.36301058 0.214077 1773 318 0.37100331 0.259716 1773 319 0.38405288 0.306186 1773 320 0.40362816 0.349985 1773 321 0.41329562 0.395798 1773 322 0.44000388 0.434682 1773 323 0.44340953 0.480386 1773 324 0.44170999 0.521847 1773 325 0.44880483 0.567886 1773 326 0.44754614 0.606240 1773 327 0.43829113 0.651879 1773 328 0.43014986 0.697418 1773 329 0.40816814 0.741452 1773 330 0.41000674 0.779668 1773 331 0.40465177 0.826003 1773 332 0.34777252 0.868745 1773 333 0.32310745 0.914606 1773 334 0.18171237 0.955580 1773 335 0.26951496 0.040750 2001 336 0.37914212 0.080921 2001 337 0.40401647 0.118653 2001 338 0.42272825 0.159287 2001 339 0.43048811 0.197259 2001 340 0.46236016 0.240817 2001 341 0.50902284 0.279548 2001 342 0.52259916 0.318519 2001 343 0.53243477 0.361549 2001 344 0.54973030 0.400000 2001 345 0.53761080 0.439565 2001 346 0.51653397 0.480386 2001 347 0.49107186 0.521847 2001 348 0.44538828 0.561354 2001 349 0.43004423 0.600000 2001 350 0.42084156 0.641002 2001 351 0.42922927 0.678666 2001 352 0.41879440 0.722318 2001 353 0.32868583 0.761244 2001 354 0.29564826 0.800000 2001 355 0.23628702 0.843440 2001 356 0.20310825 0.876633 2001 357 0.13773623 0.921480 2001 358 0.12074184 0.960888 2001 359 0.39968960 0.046814 2003 360 0.57863824 0.101623 2003 361 0.65666614 0.151987 2003 362 0.67908133 0.197259 2003 363 0.67341823 0.249102 2003 364 0.65522550 0.298996 2003 365 0.64079619 0.349985 2003 366 0.64435662 0.395798 2003 367 0.63861925 0.452095 2003 368 0.63588759 0.500000 2003 369 0.61311017 0.550281 2003 370 0.62738351 0.606240 2003 371 0.61852138 0.651879 2003 372 0.58223709 0.697418 2003 373 0.54161098 0.749612 2003 374 0.48646018 0.805637 2003 375 0.38459670 0.851205 2003 376 0.38043597 0.901224 2003 377 0.27075957 0.946148 2003 378 0.38036247 0.037328 2122 379 0.40276000 0.074093 2122 380 0.39612914 0.113468 2122 381 0.42791423 0.151987 2122 382 0.42825796 0.190470 2122 383 0.46095690 0.229281 2122 384 0.48521779 0.267528 2122 385 0.49731865 0.306186 2122 386 0.54605868 0.345469 2122 387 0.54933640 0.383389 2122 388 0.55525115 0.421442 2122 389 0.55625728 0.459525 2122 390 0.55072754 0.497546 2122 391 0.55657463 0.537179 2122 392 0.53676362 0.574251 2122 393 0.50652415 0.613815 2122 394 0.48860251 0.651879 2122 395 0.47683604 0.690939 2122 396 0.44212102 0.729257 2122 397 0.39612914 0.767440 2122 398 0.38528248 0.805637 2122 399 0.34693920 0.843440 2122 400 0.29693585 0.883711 2122 401 0.26873795 0.921480 2122 402 0.22797492 0.960888 2122 403 0.24762581 0.033511 2125 404 0.29675779 0.062335 2125 405 0.32531104 0.094141 2125 406 0.33472047 0.126127 2125 407 0.34663074 0.159287 2125 408 0.35390041 0.197259 2125 409 0.36387951 0.222673 2125 410 0.37320407 0.259716 2125 411 0.38901117 0.291917 2125 412 0.39308746 0.322916 2125 413 0.40142535 0.355376 2125 414 0.41491642 0.387903 2125 415 0.42316665 0.421442 2125 416 0.41814693 0.452095 2125 417 0.40435419 0.484540 2125 418 0.37175904 0.516730 2125 419 0.38099944 0.550281 2125 420 0.38516053 0.581372 2125 421 0.37985668 0.613815 2125 422 0.37717678 0.646015 2125 423 0.30406241 0.678666 2125 424 0.34248509 0.709662 2125 425 0.32696141 0.741452 2125 426 0.29019762 0.773048 2125 427 0.28639182 0.805637 2125 428 0.16112100 0.837162 2125 429 0.15240521 0.868745 2125 430 0.14023783 0.901224 2125 431 0.11144973 0.934460 2125 432 0.04684425 0.967649 2125 433 0.12738818 0.033511 3355 434 0.12032137 0.068081 3355 435 0.19246996 0.101623 3355 436 0.30021305 0.137577 3355 437 0.39536852 0.170015 3355 438 0.43191219 0.207414 3355 439 0.45271647 0.240817 3355 440 0.47445420 0.274229 3355 441 0.48947320 0.311311 3355 442 0.51200729 0.345469 3355 443 0.51159131 0.377397 3355 444 0.50573160 0.414996 3355 445 0.50671293 0.446316 3355 446 0.49885571 0.480386 3355 447 0.47911798 0.516730 3355 448 0.48398125 0.550281 3355 449 0.45930461 0.586440 3355 450 0.44893852 0.619709 3355 451 0.42866861 0.655532 3355 452 0.40953422 0.690939 3355 453 0.37415759 0.722318 3355 454 0.34808624 0.754480 3355 455 0.34998393 0.793380 3355 456 0.31834044 0.826003 3355 457 0.24694972 0.862719 3355 458 0.22192562 0.895078 3355 459 0.17830631 0.929464 3355 460 0.17509332 0.964828 3355 461 0.23328477 0.046814 3356 462 0.29713891 0.094141 3356 463 0.33913003 0.137577 3356 464 0.39302555 0.184325 3356 465 0.42662490 0.229281 3356 466 0.45006759 0.274229 3356 467 0.45955706 0.318519 3356 468 0.46964286 0.361549 3356 469 0.47564354 0.408420 3356 470 0.47304390 0.452095 3356 471 0.44970213 0.500000 3356 472 0.42720259 0.543154 3356 473 0.41737157 0.592719 3356 474 0.39780731 0.632230 3356 475 0.35407259 0.685227 3356 476 0.30057734 0.729257 3356 477 0.20794585 0.773048 3356 478 0.20253853 0.818738 3356 479 0.16693878 0.862719 3356 480 0.08553668 0.907147 3356 481 0.03007141 0.955580 3356 482 0.12522795 0.037328 2873 483 0.12723816 0.074093 2873 484 0.14477616 0.106794 2873 485 0.15411502 0.143437 2873 486 0.21348148 0.176730 2873 487 0.26271901 0.214077 2873 488 0.27856451 0.252096 2873 489 0.31723668 0.285536 2873 490 0.34120764 0.318519 2873 491 0.36044750 0.355376 2873 492 0.36332243 0.395798 2873 493 0.36755816 0.428268 2873 494 0.37460158 0.465443 2873 495 0.38178095 0.500000 2873 496 0.38118229 0.537179 2873 497 0.36989800 0.574251 2873 498 0.35641212 0.606240 2873 499 0.33814474 0.641002 2873 500 0.30921638 0.678666 2873 501 0.28200482 0.715608 2873 502 0.26425989 0.754480 2873 503 0.25337707 0.788056 2873 504 0.24647287 0.818738 2873 505 0.22176036 0.857893 2873 506 0.16676785 0.895078 2873 507 0.11398351 0.929464 2873 508 0.05037407 0.964828 2873 509 0.27228222 0.028771 2874 510 0.34193313 0.062335 2874 511 0.39443653 0.094141 2874 512 0.42802678 0.126127 2874 513 0.43522858 0.159287 2874 514 0.43105717 0.190470 2874 515 0.44967499 0.222673 2874 516 0.46696994 0.249102 2874 517 0.47057562 0.279548 2874 518 0.47811186 0.311311 2874 519 0.47603496 0.338177 2874 520 0.47778667 0.377397 2874 521 0.48030114 0.408420 2874 522 0.48376732 0.434682 2874 523 0.47758331 0.470750 2874 524 0.47316947 0.500000 2874 525 0.46672024 0.530893 2874 526 0.47349784 0.561354 2874 527 0.45448816 0.592719 2874 528 0.44419784 0.624610 2874 529 0.43478196 0.655532 2874 530 0.36181003 0.685227 2874 531 0.37885981 0.715608 2874 532 0.38476236 0.749612 2874 533 0.36972431 0.779668 2874 534 0.34385953 0.811593 2874 535 0.24493663 0.843440 2874 536 0.24109927 0.876633 2874 537 0.21870520 0.907147 2874 538 0.19573503 0.939046 2874 539 0.19263348 0.967649 2874
fit2 <- nlme::nlme(y ~ nfun(x, b0, b1, b2), data = dd.gr, fixed = b0 + b1 + b2 ~ 1, random = b0 ~ 1 | id, start = start.dd, method = "REML")
Successive prime numbers in R [duplicate]
This question already has answers here: What does the diff() function in R do? [closed] (2 answers) Closed 5 years ago. I'm using RStudio and am pretty new to R. I have a dataset that shows the prime numbers from 1- 301. How do you use the diff function to compute the differences between successive primes? Here is my dataset: [1] 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 [31] 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 [61] 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 [91] 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 [121] 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 [151] 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021 1031 1033 1039 1049 1051 1061 1063 1069 [181] 1087 1091 1093 1097 1103 1109 1117 1123 1129 1151 1153 1163 1171 1181 1187 1193 1201 1213 1217 1223 1229 1231 1237 1249 1259 1277 1279 1283 1289 1291 [211] 1297 1301 1303 1307 1319 1321 1327 1361 1367 1373 1381 1399 1409 1423 1427 1429 1433 1439 1447 1451 1453 1459 1471 1481 1483 1487 1489 1493 1499 1511 [241] 1523 1531 1543 1549 1553 1559 1567 1571 1579 1583 1597 1601 1607 1609 1613 1619 1621 1627 1637 1657 1663 1667 1669 1693 1697 1699 1709 1721 1723 1733 [271] 1741 1747 1753 1759 1777 1783 1787 1789 1801 1811 1823 1831 1847 1861 1867 1871 1873 1877 1879 1889 1901 1907 1913 1931 1933 1949 1951 1973 1979 1987 [301] 1993 1997 1999 2003 Would appreciate some help, thanks!
You simply call diff(primes) For a simple dataset: > primes <- c(2,3,5,7) > diff(primes) [1] 1 2 2
Get a sublist of a list
I have a vector which is around 3000 elements long. I have extracted a specific point in the vector with which(...). Now I want to have -120 before this point and +120 after this point. My list looks like that: > testList$Date [1] "01.01.2002" "02.01.2002" "03.01.2002" "04.01.2002" "07.01.2002" [6] "08.01.2002" "09.01.2002" "10.01.2002" "11.01.2002" "14.01.2002" [11] "15.01.2002" "16.01.2002" "17.01.2002" "18.01.2002" "21.01.2002" [16] "22.01.2002" "23.01.2002" "24.01.2002" "25.01.2002" "28.01.2002" [21] "29.01.2002" "30.01.2002" "31.01.2002" "01.02.2002" "04.02.2002" [26] "05.02.2002" "06.02.2002" "07.02.2002" "08.02.2002" "11.02.2002" [31] "12.02.2002" "13.02.2002" "14.02.2002" "15.02.2002" "18.02.2002"ect.... I could do a for-loop to iterate over the list and save this as a sublist. However, I do not think that is very efficient. How can I implement that in R? I appreciate your answer! UPDATE When using lapply I get: > 120BeforeSublist <- lapply(event, function(x) c(x-120, x)) > (120BeforeSublist) [[1]] [1] 1875 1995 However I want to have the sublist saved -120 before and +120 after.
Does that describe your problem in principle, and a generic solution: x <- 1:20 pos <- which( x == 10 ) end <- 2 len <- 5 x_bef <- x[ ( pos - len - end ) : ( pos - end ) ] x_aft <- x[ (pos + end ) : ( pos + len + end ) ] x_bef [1] 3 4 5 6 7 8 x_aft [1] 12 13 14 15 16 17
How about something like this: i <- which(...) boundaries <- lapply(i, function(x) (x-120):(x+120)) An example: > i <- c(350, 465, 2700) # Points of interest > boundaries <- lapply(i, function(x) (x-120):(x+120)) > boundaries [[1]] [1] 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 [19] 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 [37] 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 [55] 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 [73] 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 [91] 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 [109] 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 [127] 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 [145] 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 [163] 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 [181] 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 [199] 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 [217] 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 [235] 464 465 466 467 468 469 470 [[2]] [1] 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 [19] 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 [37] 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 [55] 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 [73] 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 [91] 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 [109] 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 [127] 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 [145] 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 [163] 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 [181] 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 [199] 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 [217] 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 [235] 579 580 581 582 583 584 585 [[3]] [1] 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 [16] 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 [31] 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 [46] 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 [61] 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 [76] 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 [91] 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 [106] 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 [121] 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 [136] 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 [151] 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 [166] 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 [181] 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 [196] 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 [211] 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 [226] 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 [241] 2820