Apply function to data grouped by cut() - r
I would like some help with summarising data using cut. I have been successful in less complicated situations, but now I am stuck.
The data:
> dput(sumsq)
structure(list(part_no = c(10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L), ratperc = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8,
0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, 0, 0, 0, 0,
0, 0, 75.6, 0, 89.6, 24.8, -100, -100, 75.6, 100, 100, -100,
-100, -100, -100, -100, -100, 75.6, 98.4, 98.4, -51.2, -51.2,
0.8, 0.8, 0.4, 0.4, 0.4, 0.4, 75.2, -100, -100, -100, 1.2, -0.4,
-0.4, -0.4, -0.4, 100, 100, -1.6, 0, 0, 0, 0, -100, 0.4, 100,
0.4, 0.4, 100, -0.4, -78.4, 0.4, 100, 100, 100, 100, -100, 23.6,
61.2, 61.2, 69.2, 75.6, 75.6, 75.6, 75.6, 75.6, 98, 98, 98, -75.2,
-75.2, 47.2, 47.2, 47.2, 47.2, 76.8, 97.6, -71.6, -71.6, -71.6,
-71.6, 24, 52, 52, 52, 75.2, 75.2, -77.6, 25.2, 47.2, 76.4, 76.4,
76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4, 76.4,
76.4, -73.2, -73.2, -73.2, -73.2, 0.8, 0.8, 75.2, 75.2, 75.2,
75.2, 75.2, 75.2, 0.4, 0.4, 0.4, 0.4, 0.4, -100, -100, -100,
-100, -100, 73.2, 2, -0.8, -0.8, -0.8, -100, -0.4, -0.4, 50.4,
50.4, 50.4, 50.4, 50.4, 50.4, -76.4, 99.6, 99.6, -76.4, 100,
100, 50.4, 1.2, 28, -1.2, 93.6, 41.2, 1.6, 24.8, -1.6, 0, 0,
24.8, -24, 26, 50.8, 2, 28, 36.4, 24, -43.6, 33.6, 61.2, 81.2,
86.8, 34, -51.6, -2, 28.4, 2, 82, 41.6, 25.6, 82, 0.8, 92, 1.2,
86.4, 54, 96, 0.4, -54.4, 1.2, -93.2, -49.2, -98.4, -2, -77.2,
93.2, 23.6, 78.8, 42.4, 0.4, 2.8, 70.8, 24.4, 2.4, 62, 92.8,
16.4, -61.2, 24.4, -77.2, -0.4, 74.8, 3.6, 82, 82, 18, 54, 9.2,
55.2, 96.4, 96.4, 90, 90, -84.4, -84.4, -2.8, -2, -90.4, 2.4,
34.8, 24, -1.6, -16.8, 2.8, 2.4, -83.2, 22.4, 22.4, -1.6, -1.6,
60, -2.4, 2.4, 2, 0.8, -22.8, 2, -1.6, 25.2, 2, 2, -52.8, -1.2,
-1.2, 3.2, -74.4, 3.2, 3.2, -78.4, 0.4, -2.4, 0.4, 0.4, 0.4,
0.4, 0.4, 0.4, -79.2, -0.8, -0.8, -0.8, -0.8, -0.8, -3.2, 41.2,
-0.8, -0.8, -0.8, -0.8, -83.2, -1.6, -1.6, 0.4, 0.4, 0.4, -90,
-1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6, -1.6,
77.6, -79.6, 80.8, -81.6, -93.2, -100, 8.4, 75.6, 82.8, 67.2,
-27.2, 78.8, 65.6, 84.8, 73.6, 46.8, -62.4, 57.2, 74, 13.6, -0.8,
32.8, -27.2, 6.4, -67.2, 79.2, -64, 58, -40.4, 64, 8, 60, 76.8,
-24.8, -52.4, 56.8, 75.6, 38.4, -50.4, -72.8, -83.6, 24, 34.8,
54.4, -54, 67.6, 78.4, -41.6, -64.4, -83.6, -93.6, 76.8, -2.4,
-19.2, -54, -38, 5.2, 52.4, 64.8, 42.4, 77.6, -46.4, -74.8, -60.4,
-83.2, -56.4, -34.8, -16.8, 21.2, 40, 59.2, 0.4, -17.6, 24.4,
-14.4, 35.2, -26.8, 42, 44, -1.2, -35.6, 10.8, -19.6, -35.2,
22.4, -18.4, 27.6, -9.6, 43.2, -31.2, 45.2, 23.6, -16.4, 28.8,
40.4, 25.6, -8, 15.6, 11.2, -17.2, 15.6, -17.6, 18, 24, -9.6,
-34.8, 12.4, -17.2, 36.4, -9.2, -35.2, -19.6, 10.4, -15.6, -30.4,
30.8, 16.4, -14.8, -26.4, -34.4, 52.8, 34.4, 55.6, 21.2, 41.2,
52, 36.8, 50, 15.6, 36, 53.6, -22.8, 14.8, 25.2, -13.2, -18.8,
32, 20.8, -6.8, -16.4, -27.6, 14.4, 26.8, 38, -28.4, 19.6, -23.6,
18.4, -19.6, 11.6, 0, 0, 0, -26, -52.4, -24.4, 2, 19.6, -10.8,
3.6, 3.6, -25.2, 28.4, 12, -11.2, 3.2, 37.2, 26, 0.8, 47.6, -17.2,
2.4, -12, -52.4, 0.8, 28.4, -12, 36.4, 2.4, 50.4, -16, 24.4,
-2.4, -2.4, 15.2, -1.6, -1.6, -1.6, 24.4, -36, 33.2, 1.2, 1.2,
-48.8, -22.4, -1.2, -100, -1.6, -1.6, -26.4, 28, -47.6, 86, -1.6,
-1.6, -1.6, -1.6, -1.6, 41.6, -16, 29.6, -14.8, 3.2, 3.2, 100,
0.8, 0.8, 0.8, 0.8, 25.6, 24.8, -28, 0.8, -39.2, -97.6, -97.6,
-50, 0, 0, 49.6, 0.8, 54, 25.6, -1.2, -1.2, -90.8, 4.4, 4.4,
41.6, -40.8, -6, -6, 51.6, -8.4, 0, 0, 0, -60, 2.8, -52.4, 1.6,
1.6, 1.6, 18.8, 24.4, -0.4, -0.4, -0.4, -0.4, -51.6, -0.4, -0.4,
-0.4, 26, 0, 18, -42.4, -1.6, -0.4, 60.4, -2.8, -2.8, -2.8, 76,
2.8, 2.8, -29.2, -23.2, 23.6, -26.8, 0.4, 0.4, -40.8, -3.6, -47.6,
27.6, -2.4, -2.4, -76, -2, -2, -2, -30.8, 26.8, -4.4, -4.4, -4.4,
3.6, -0.8, -0.8, 67.2, -1.2, -48.8, 63.2, -42, 50, 30.8, 57.6,
-48.8, -48.8, 41.6, -39.2, -39.2, -35.6, 40, -44, -39.6, -39.6,
-50.8, 0, -48.8, 40, -53.2, 52, -47.2, -47.2, -46, 26.4, -29.2,
0, -46.8, -46.8, 34.8, -43.6, 0, 39.2, 0.4, -48.4, 0, -23.6,
29.2, 29.2, -53.2, -53.2, 19.2, 46.4, 46.4, -2, 36, 2, -25.2,
-50, -1.6, -2, 35.2, -32.8, 31.2, -43.2, 46, -28.8, -0.4, -50.4,
0.8, -43.6, 0.4, 27.6, -37.6, -37.6, 37.6, -50, 40.8, -0.8, -50.4,
-49.6, 45.6, 45.6, -48.8, -0.8, -54, -54, 43.2, -48.8, 46.4,
-42.8, 54, -54.4, 34.8, 0.4, 0.4, 0.4, 0.8, -50.4, -50.8, -50.8,
51.6, -68.8, 0.8, 52, -42, -42, 0, -56.8, -56.8, 0.8, -48, -46.4,
-46.8, -46.8, 0.4, 0.4, 37.2, -36.8, -36.8, -0.4, -0.4, -0.4,
-0.4, -0.4, -48.8, 0.8, 0.8, 58.8, 2, 2, 2, 2, 29.2, -50.4, 49.6,
41.2, -39.2, 38.8, -38.8, 28, -38, 40.8, 0.8, 0.8, 0.8, 0.8,
0.8, -51.2, 27.2, -54.8, 0.8, 0.8, -40.4, -40.4, 0, -46.8, 35.2,
-50.4, 9.6, -0.4, -15.2, 17.6, -26.8, -14.4, 42.8, 18.8, 2.8,
0, -33.2, -36.4, -7.6, 18.8, 34.4, 8.8, -25.6, -16.8, -10, -50.8,
10, -11.2, -7.2, -15.2, -62.8, 27.6, -12.8, -1.2, -24.4, 18.8,
-7.2, 37.2, 8.4, -40, -9.6, 20, -27.2, 27.2, 7.2, -31.6, -31.6,
27.6, -1.6, -20, -20, 34.4, 18, -23.6, 28.4, -16, 15.2, -30.4,
-9.2, -7.6, 12.4, 23.2, 15.6, 23.2, 37.2, -8.8, -21.6, -31.6,
-23.2, 25.2, 33.2, 9.2, 34.4, 18, 5.2, -50.4, 34.8, 12.4, -13.6,
-7.2, 6.4, 15.2, 2, 12.8, -14.4, 32.4, 15.6, 23.2, 30, -11.6,
-34.8, 12, -24, -11.2, -41.2, 34.4, 18.8, 18.8, 12, 37.6, 10,
35.2, -24.4, 24.8, 40.4, 52.4, 14, -41.6, 34, 43.2, -6, -28,
24, 35.2, 26.8, -15.2, 28, 38.8, 11.6, 57.6, 28, 12, -18.8, 35.6,
25.2, 40.4, 59.2, -58.4, 10.4, -23.6, 18, -14, 35.2, 13.6, 48.4,
32.8, 32.8, -17.2, -11.2, 26, -24, 15.2, -66.4, 24.4, -30.4,
39.6, 30, 53.2, 59.6, -40.4, -14, 36, 36, 41.6, 32, 57.6, 8.4,
62, 85.6, 85.6, 84.4, 38, 63.2, 67.2, -42.8, 63.6, 95.2, 65.2,
86.8, 87.2, 9.2, 83.2, 11.6, 83.2, 83.2, 79.6, 63.2, 88.8, -62,
-84.8, -84.8, -86.8, -4.4, 87.2, 86, 17.2, 81.6, -60.8, -87.6,
80, 37.2, -64.8, 86.4, 87.2, 94.4, 94, -61.6, 86.8, 86.4, 86.8,
86, -86, 94.4, -87.6, 80, 84.8, 86.8, -64.8, 85.2, 83.2, -90.8,
88.8, 85.6, 85.2, 87.2, 85.2, 85.6, -64, 84.8, 84.4, -90, 84.8,
82, -83.6, 88.4, 92, 80.8, 79.6, 80.4, 78.4, 78.4, 80, 80, 79.2,
81.2, 84.8, -78.4, 80.8, -88.8, 81.6, 81.6, -64.8, -85.6, 89.2,
90.4, -84, 85.2, -32.8, 49.6, 83.2, 81.2, 79.2, 80, 85.6, 81.6,
34.4, -85.6, 83.6, 82.4, 84, 81.2, 85.6, 85.6, 87.6, 84.8, 85.6,
82.8, -86.4, -60, 36.8, -85.6, 86.4, -65.6, 81.6, -81.2, 92.8,
-86.4, 84.8, 63.2, 36, 86.4, 86.4, 82.4, 83.2, 82.8, 82.4, 80.8,
80.4, 80.4, -63.6, 84.8, 84.8, 68, 93.2, 88, 89.6, 33.6, 83.6,
-67.2, 88.8, 88, 85.2, -39.6, 84.8), diffdist = c(-9L, -7L, -16L,
-17L, -38L, 55L, -17L, -2L, -18L, -24L, -7L, 24L, -40L, -35L,
69L, -42L, -15L, 80L, 73L, -28L, 39L, -46L, 40L, -49L, 11L, -9L,
-6L, -50L, 71L, 23L, -69L, -1L, 8L, 37L, -29L, -16L, 25L, -8L,
-44L, 27L, -20L, -11L, 16L, -16L, 40L, -57L, -13L, 13L, 40L,
-7L, 51L, -19L, -2L, -9L, 22L, 35L, -13L, -20L, -4L, -64L, 0L,
-48L, -55L, -19L, 20L, 6L, 31L, 9L, -62L, -4L, -50L, 39L, 53L,
-22L, 33L, 58L, 62L, -37L, 5L, -5L, 36L, 35L, -9L, 16L, -42L,
-20L, 7L, 24L, 29L, -80L, 41L, -18L, -28L, -16L, 6L, 15L, -37L,
52L, -12L, -40L, 64L, -28L, 22L, 29L, -4L, -47L, -3L, -61L, -2L,
21L, 3L, 9L, 35L, 73L, -20L, -8L, -53L, -19L, -11L, -6L, -56L,
17L, -20L, -66L, -16L, -29L, 26L, -29L, 44L, 38L, 40L, 51L, 84L,
-33L, -33L, -6L, -71L, -14L, -13L, -47L, 21L, 5L, -9L, -42L,
-26L, 35L, 53L, 2L, -6L, 31L, -22L, -70L, -17L, 35L, -55L, 9L,
-14L, 2L, 11L, -71L, 49L, 30L, -40L, -77L, 15L, 53L, -29L, 51L,
68L, -5L, -24L, -75L, -60L, -27L, -43L, -5L, -3L, -31L, -22L,
8L, -43L, 9L, -43L, -35L, 70L, -47L, -23L, 25L, -64L, 0L, -24L,
-17L, 68L, -12L, -57L, 28L, -9L, 42L, 35L, 21L, 13L, 9L, -9L,
-12L, 31L, -6L, -8L, -33L, 20L, -4L, -53L, 37L, -33L, 21L, 68L,
-28L, -56L, 61L, -69L, -12L, 9L, -23L, -60L, -9L, -7L, 45L, -44L,
-33L, 47L, -7L, 53L, -2L, -13L, -18L, 57L, -2L, 45L, 40L, -18L,
9L, -21L, 22L, 4L, 27L, 27L, -63L, -62L, -59L, 13L, -3L, -62L,
2L, 23L, 52L, 20L, -18L, 52L, 40L, -51L, -24L, -18L, -29L, -47L,
-33L, 64L, -74L, -36L, 18L, -36L, 22L, 8L, -46L, 24L, 4L, -74L,
-3L, 18L, -53L, 20L, 60L, -9L, -19L, 15L, 31L, 18L, 35L, 24L,
11L, -40L, -64L, 33L, -31L, 8L, 58L, 41L, -33L, -53L, -35L, 2L,
-19L, 42L, -53L, 64L, 46L, -53L, 62L, -77L, -18L, -3L, -11L,
33L, -67L, 68L, 0L, 51L, 13L, -11L, 40L, -65L, 22L, 39L, -5L,
76L, -44L, -35L, 15L, 0L, 13L, 7L, 6L, -51L, -44L, -20L, 20L,
11L, -55L, -66L, -49L, 4L, -58L, -27L, 20L, -16L, 42L, -69L,
71L, -68L, -42L, 44L, 31L, -13L, -63L, -72L, -13L, 19L, 39L,
-13L, 71L, -53L, -33L, 67L, -42L, 14L, 39L, 33L, -13L, -19L,
73L, -71L, -24L, 11L, 0L, -42L, -71L, -1L, -62L, -11L, -7L, 18L,
49L, 8L, -21L, -5L, 13L, -38L, 62L, -15L, -27L, 0L, -33L, 9L,
-40L, -57L, 60L, 73L, -24L, 0L, 22L, -37L, -46L, -27L, 27L, 0L,
6L, 77L, -13L, 47L, 71L, -20L, 11L, 18L, 31L, 8L, 80L, -87L,
-20L, 57L, -37L, 24L, 62L, -11L, -50L, 9L, 52L, 7L, 2L, -57L,
-50L, 69L, 7L, -42L, -43L, -22L, 46L, 57L, 24L, 35L, 9L, -54L,
51L, 6L, -8L, -8L, 9L, 48L, 24L, 31L, -55L, 53L, 44L, 7L, -7L,
22L, -53L, 42L, -44L, -2L, 6L, -9L, -5L, 33L, -20L, 20L, 36L,
39L, -16L, -25L, 44L, -28L, 4L, -4L, -47L, -87L, 6L, -38L, 51L,
-9L, 37L, -47L, 72L, -19L, 26L, 37L, -43L, 29L, -11L, 54L, 4L,
-41L, -24L, -55L, 11L, 35L, 22L, 57L, 61L, 40L, -52L, -17L, 10L,
28L, -24L, -28L, -3L, -9L, -47L, 40L, 35L, 57L, 13L, 13L, 33L,
24L, 22L, -67L, -49L, -77L, 7L, -36L, 9L, 29L, -16L, -5L, 11L,
-13L, 57L, -17L, 49L, 66L, -55L, -33L, -6L, -29L, 5L, -62L, 80L,
33L, 73L, 87L, -3L, 18L, 40L, 18L, 70L, 49L, 55L, 5L, -13L, 9L,
-17L, 36L, -22L, 9L, 0L, -75L, -40L, -12L, 17L, 19L, -9L, 13L,
-15L, -51L, 10L, -20L, 1L, 3L, 40L, 38L, 19L, 11L, 0L, 89L, -10L,
49L, 44L, 75L, 83L, -8L, 36L, -60L, 38L, -53L, -19L, 11L, 4L,
-53L, -51L, -11L, 71L, 20L, 7L, -33L, 37L, 3L, 49L, 22L, -57L,
-74L, -30L, 22L, 11L, -9L, -19L, -51L, -42L, 3L, 55L, -42L, -7L,
-19L, -53L, 32L, -73L, 11L, -9L, -31L, 20L, -5L, 55L, -26L, -22L,
-28L, 75L, -15L, -58L, 20L, 37L, -26L, -57L, -50L, -47L, -35L,
-20L, 22L, 1L, 28L, 0L, -38L, 24L, 40L, 22L, -33L, 34L, -28L,
-18L, 33L, -57L, 4L, -13L, -25L, -62L, 33L, -62L, 55L, 28L, -9L,
14L, -50L, -18L, -40L, 20L, 24L, -53L, -27L, 23L, 4L, 13L, 27L,
-55L, -4L, 44L, 4L, -9L, -17L, -44L, -42L, 18L, -33L, -44L, 17L,
-53L, -13L, -24L, -56L, -41L, 28L, 31L, 21L, -13L, 27L, -46L,
-50L, -25L, 29L, -7L, -6L, -11L, -18L, 71L, -69L, -50L, -3L,
2L, 18L, -24L, -40L, -15L, -46L, 11L, 29L, 10L, -30L, 7L, -13L,
50L, 77L, 2L, 9L, -71L, -9L, -62L, -55L, 29L, 38L, -48L, -22L,
-30L, 39L, -44L, 42L, -5L, -61L, 16L, 24L, -46L, 2L, 4L, -8L,
-16L, 33L, -35L, 80L, -39L, 19L, -55L, -23L, -46L, 2L, 7L, -77L,
-5L, 18L, -44L, -18L, -62L, -62L, -84L, 85L, 13L, 49L, 11L, 41L,
40L, -38L, 15L, 39L, -13L, 39L, -11L, -64L, 58L, 35L, -18L, 34L,
18L, 24L, -22L, -4L, -46L, -71L, 22L, -44L, -49L, -11L, -40L,
-4L, 11L, -5L, 37L, -24L, -27L, -33L, 52L, -11L, 9L, -54L, 0L,
-24L, 0L, 18L, 13L, -17L, 22L, 64L, 58L, 71L, -6L, -24L, 29L,
-3L, -22L, -9L, 55L, -9L, -16L, -35L, 56L, 25L, -58L, -26L, -9L,
62L, -48L, -62L, 9L, 35L, -8L, 33L, 40L, 55L, 40L, 35L, -23L,
11L, 46L, 62L, -15L, -2L, -9L, -17L, 39L, 15L, -13L, -37L, 20L,
-7L, -14L, 70L, 28L, -2L, 55L, -25L, 6L, -36L, 30L, 62L, 66L,
11L, 24L, -42L, 58L, 9L, 45L, 4L, 0L, -20L, 20L, 27L, -4L, 3L,
-40L, -2L, 2L, 10L, 8L, 20L, -24L, -39L, -13L, 20L, -45L, -76L,
-46L, 3L, -55L, -18L, 22L, 2L, -14L, -20L, -26L, 51L, -66L, -9L,
0L, 51L, 22L, -12L, 27L, -35L, 11L, 38L, -3L, 15L, 4L, -55L,
44L, -55L, -46L, 6L, -46L, 22L, 22L, 46L, 20L, 35L, -11L, -20L,
-53L, 51L, -80L, -59L, -53L, -78L, -36L, -13L, 31L, 33L, -9L,
-26L, 31L, -14L, -16L, -15L, -53L, 9L, 65L, 3L, 44L, -42L, 45L,
-13L, -7L, -6L, 52L, 60L, -3L, -3L, 7L, -40L, 2L, 29L, 11L, 33L,
40L, -16L, -9L, -21L, 78L, -60L, 15L, 0L, 17L, -15L, -18L, 48L,
26L, 31L, -53L, -9L, -3L, -1L, 64L, 7L, 44L, -38L, -23L, 13L,
55L, 57L, -71L, -20L, 23L, -18L, 4L, 16L, -7L, 52L, 42L, 24L,
5L, -2L, 6L, -33L, 9L, 30L, -51L, 58L, 53L, -44L, -22L, -44L,
-75L, -60L, 46L, 14L, 13L, -5L, -7L, 69L, -18L, 53L, 52L, -62L,
-13L, 22L, 64L, -18L, 71L, 24L, -9L, 68L, -40L, -10L, -2L, 12L,
37L, 40L, 79L, 3L, 42L, -55L, 7L, -31L, 20L, 16L, 7L, 11L, -14L,
70L, 24L, 3L, -57L, -14L, 51L, -19L, -62L, -16L, -2L, -68L, 4L,
7L, -20L, 4L, -15L, 49L, -16L, 11L, 6L, 56L, -6L, 68L, 28L, 33L,
-62L, 20L, -39L, -12L, -45L, -30L, -15L, 37L, 44L, 39L, 38L,
46L, 33L, 2L, -3L, 29L, 44L, 2L, -57L, 37L, 42L, 20L, 5L, 53L,
-51L, 11L, -5L, -24L, 7L, 29L, -20L, -15L, 24L, 80L, 4L, 82L,
29L, -24L, 68L, -38L, 27L, 71L, 30L, 42L, 14L, -75L, -41L, 22L,
46L, -72L, -53L, 78L, 54L, 22L, -55L, 57L, -1L, -54L, 80L, 68L,
-17L, -18L, -3L, 5L, 16L, -39L, -21L, -29L, -64L, -5L, 46L, -8L,
3L, -15L, 26L, -6L, 38L, -2L, -13L, -62L, -51L, -60L, 9L, -64L,
51L, 31L, 36L, 0L, -35L, 29L, 22L, 31L, -2L, 14L, 73L, -17L,
17L, -58L, 55L, 37L, -16L, 71L, 28L, 72L, -26L, 22L, 12L, 25L,
23L, -46L, -9L, -55L, -7L, 18L, -40L, 28L, -9L, 5L, -6L, 26L,
58L, 31L, -38L, -27L, 14L, -34L, -5L, 9L, 20L, -35L, 31L, -3L,
-19L, -33L, 34L)), .Names = c("part_no", "ratperc", "diffdist"
), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L,
38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L,
51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L,
64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L,
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L,
90L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L,
102L, 103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L,
113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L,
124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L,
135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L,
146L, 147L, 148L, 149L, 150L, 301L, 302L, 303L, 304L, 305L, 306L,
307L, 308L, 309L, 310L, 311L, 312L, 313L, 314L, 315L, 316L, 317L,
318L, 319L, 320L, 321L, 322L, 323L, 324L, 325L, 326L, 327L, 328L,
329L, 330L, 331L, 332L, 333L, 334L, 335L, 336L, 337L, 338L, 339L,
340L, 341L, 342L, 343L, 344L, 345L, 346L, 347L, 348L, 349L, 350L,
351L, 352L, 353L, 354L, 355L, 356L, 357L, 358L, 359L, 360L, 361L,
362L, 363L, 364L, 365L, 366L, 367L, 368L, 369L, 370L, 371L, 372L,
373L, 374L, 375L, 376L, 377L, 378L, 379L, 380L, 381L, 382L, 383L,
384L, 385L, 386L, 387L, 388L, 389L, 390L, 391L, 392L, 393L, 394L,
395L, 396L, 397L, 398L, 399L, 400L, 401L, 402L, 403L, 404L, 405L,
406L, 407L, 408L, 409L, 410L, 411L, 412L, 413L, 414L, 415L, 416L,
417L, 418L, 419L, 420L, 421L, 422L, 423L, 424L, 425L, 426L, 427L,
428L, 429L, 430L, 431L, 432L, 433L, 434L, 435L, 436L, 437L, 438L,
439L, 440L, 441L, 442L, 443L, 444L, 445L, 446L, 447L, 448L, 449L,
450L, 601L, 602L, 603L, 604L, 605L, 606L, 607L, 608L, 609L, 610L,
611L, 612L, 613L, 614L, 615L, 616L, 617L, 618L, 619L, 620L, 621L,
622L, 623L, 624L, 625L, 626L, 627L, 628L, 629L, 630L, 631L, 632L,
633L, 634L, 635L, 636L, 637L, 638L, 639L, 640L, 641L, 642L, 643L,
644L, 645L, 646L, 647L, 648L, 649L, 650L, 651L, 652L, 653L, 654L,
655L, 656L, 657L, 658L, 659L, 660L, 661L, 662L, 663L, 664L, 665L,
666L, 667L, 668L, 669L, 670L, 671L, 672L, 673L, 674L, 675L, 676L,
677L, 678L, 679L, 680L, 681L, 682L, 683L, 684L, 685L, 686L, 687L,
688L, 689L, 690L, 691L, 692L, 693L, 694L, 695L, 696L, 697L, 698L,
699L, 700L, 701L, 702L, 703L, 704L, 705L, 706L, 707L, 708L, 709L,
710L, 711L, 712L, 713L, 714L, 715L, 716L, 717L, 718L, 719L, 720L,
721L, 722L, 723L, 724L, 725L, 726L, 727L, 728L, 729L, 730L, 731L,
732L, 733L, 734L, 735L, 736L, 737L, 738L, 739L, 740L, 741L, 742L,
743L, 744L, 745L, 746L, 747L, 748L, 749L, 750L, 901L, 902L, 903L,
904L, 905L, 906L, 907L, 908L, 909L, 910L, 911L, 912L, 913L, 914L,
915L, 916L, 917L, 918L, 919L, 920L, 921L, 922L, 923L, 924L, 925L,
926L, 927L, 928L, 929L, 930L, 931L, 932L, 933L, 934L, 935L, 936L,
937L, 938L, 939L, 940L, 941L, 942L, 943L, 944L, 945L, 946L, 947L,
948L, 949L, 950L, 951L, 952L, 953L, 954L, 955L, 956L, 957L, 958L,
959L, 960L, 961L, 962L, 963L, 964L, 965L, 966L, 967L, 968L, 969L,
970L, 971L, 972L, 973L, 974L, 975L, 976L, 977L, 978L, 979L, 980L,
981L, 982L, 983L, 984L, 985L, 986L, 987L, 988L, 989L, 990L, 991L,
992L, 993L, 994L, 995L, 996L, 997L, 998L, 999L, 1000L, 1001L,
1002L, 1003L, 1004L, 1005L, 1006L, 1007L, 1008L, 1009L, 1010L,
1011L, 1012L, 1013L, 1014L, 1015L, 1016L, 1017L, 1018L, 1019L,
1020L, 1021L, 1022L, 1023L, 1024L, 1025L, 1026L, 1027L, 1028L,
1029L, 1030L, 1031L, 1032L, 1033L, 1034L, 1035L, 1036L, 1037L,
1038L, 1039L, 1040L, 1041L, 1042L, 1043L, 1044L, 1045L, 1046L,
1047L, 1048L, 1049L, 1050L, 1201L, 1202L, 1203L, 1204L, 1205L,
1206L, 1207L, 1208L, 1209L, 1210L, 1211L, 1212L, 1213L, 1214L,
1215L, 1216L, 1217L, 1218L, 1219L, 1220L, 1221L, 1222L, 1223L,
1224L, 1225L, 1226L, 1227L, 1228L, 1229L, 1230L, 1231L, 1232L,
1233L, 1234L, 1235L, 1236L, 1237L, 1238L, 1239L, 1240L, 1241L,
1242L, 1243L, 1244L, 1245L, 1246L, 1247L, 1248L, 1249L, 1250L,
1251L, 1252L, 1253L, 1254L, 1255L, 1256L, 1257L, 1258L, 1259L,
1260L, 1261L, 1262L, 1263L, 1264L, 1265L, 1266L, 1267L, 1268L,
1269L, 1270L, 1271L, 1272L, 1273L, 1274L, 1275L, 1276L, 1277L,
1278L, 1279L, 1280L, 1281L, 1282L, 1283L, 1284L, 1285L, 1286L,
1287L, 1288L, 1289L, 1290L, 1291L, 1292L, 1293L, 1294L, 1295L,
1296L, 1297L, 1298L, 1299L, 1300L, 1301L, 1302L, 1303L, 1304L,
1305L, 1306L, 1307L, 1308L, 1309L, 1310L, 1311L, 1312L, 1313L,
1314L, 1315L, 1316L, 1317L, 1318L, 1319L, 1320L, 1321L, 1322L,
1323L, 1324L, 1325L, 1326L, 1327L, 1328L, 1329L, 1330L, 1331L,
1332L, 1333L, 1334L, 1335L, 1336L, 1337L, 1338L, 1339L, 1340L,
1341L, 1342L, 1343L, 1344L, 1345L, 1346L, 1347L, 1348L, 1349L,
1350L, 1501L, 1502L, 1503L, 1504L, 1505L, 1506L, 1507L, 1508L,
1509L, 1510L, 1511L, 1512L, 1513L, 1514L, 1515L, 1516L, 1517L,
1518L, 1519L, 1520L, 1521L, 1522L, 1523L, 1524L, 1525L, 1526L,
1527L, 1528L, 1529L, 1530L, 1531L, 1532L, 1533L, 1534L, 1535L,
1536L, 1537L, 1538L, 1539L, 1540L, 1541L, 1542L, 1543L, 1544L,
1545L, 1546L, 1547L, 1548L, 1549L, 1550L, 1551L, 1552L, 1553L,
1554L, 1555L, 1556L, 1557L, 1558L, 1559L, 1560L, 1561L, 1562L,
1563L, 1564L, 1565L, 1566L, 1567L, 1568L, 1569L, 1570L, 1571L,
1572L, 1573L, 1574L, 1575L, 1576L, 1577L, 1578L, 1579L, 1580L,
1581L, 1582L, 1583L, 1584L, 1585L, 1586L, 1587L, 1588L, 1589L,
1590L, 1591L, 1592L, 1593L, 1594L, 1595L, 1596L, 1597L, 1598L,
1599L, 1600L, 1601L, 1602L, 1603L, 1604L, 1605L, 1606L, 1607L,
1608L, 1609L, 1610L, 1611L, 1612L, 1613L, 1614L, 1615L, 1616L,
1617L, 1618L, 1619L, 1620L, 1621L, 1622L, 1623L, 1624L, 1625L,
1626L, 1627L, 1628L, 1629L, 1630L, 1631L, 1632L, 1633L, 1634L,
1635L, 1636L, 1637L, 1638L, 1639L, 1640L, 1641L, 1642L, 1643L,
1644L, 1645L, 1646L, 1647L, 1648L, 1649L, 1650L, 1801L, 1802L,
1803L, 1804L, 1805L, 1806L, 1807L, 1808L, 1809L, 1810L, 1811L,
1812L, 1813L, 1814L, 1815L, 1816L, 1817L, 1818L, 1819L, 1820L,
1821L, 1822L, 1823L, 1824L, 1825L, 1826L, 1827L, 1828L, 1829L,
1830L, 1831L, 1832L, 1833L, 1834L, 1835L, 1836L, 1837L, 1838L,
1839L, 1840L, 1841L, 1842L, 1843L, 1844L, 1845L, 1846L, 1847L,
1848L, 1849L, 1850L, 1851L, 1852L, 1853L, 1854L, 1855L, 1856L,
1857L, 1858L, 1859L, 1860L, 1861L, 1862L, 1863L, 1864L, 1865L,
1866L, 1867L, 1868L, 1869L, 1870L, 1871L, 1872L, 1873L, 1874L,
1875L, 1876L, 1877L, 1878L, 1879L, 1880L, 1881L, 1882L, 1883L,
1884L, 1885L, 1886L, 1887L, 1888L, 1889L, 1890L, 1891L, 1892L,
1893L, 1894L, 1895L, 1896L, 1897L, 1898L, 1899L, 1900L, 1901L,
1902L, 1903L, 1904L, 1905L, 1906L, 1907L, 1908L, 1909L, 1910L,
1911L, 1912L, 1913L, 1914L, 1915L, 1916L, 1917L, 1918L, 1919L,
1920L, 1921L, 1922L, 1923L, 1924L, 1925L, 1926L, 1927L, 1928L,
1929L, 1930L, 1931L, 1932L, 1933L, 1934L, 1935L, 1936L, 1937L,
1938L, 1939L, 1940L, 1941L, 1942L, 1943L, 1944L, 1945L, 1946L,
1947L, 1948L, 1949L, 1950L, 2101L, 2102L, 2103L, 2104L, 2105L,
2106L, 2107L, 2108L, 2109L, 2110L, 2111L, 2112L, 2113L, 2114L,
2115L, 2116L, 2117L, 2118L, 2119L, 2120L, 2121L, 2122L, 2123L,
2124L, 2125L, 2126L, 2127L, 2128L, 2129L, 2130L, 2131L, 2132L,
2133L, 2134L, 2135L, 2136L, 2137L, 2138L, 2139L, 2140L, 2141L,
2142L, 2143L, 2144L, 2145L, 2146L, 2147L, 2148L, 2149L, 2150L,
2151L, 2152L, 2153L, 2154L, 2155L, 2156L, 2157L, 2158L, 2159L,
2160L, 2161L, 2162L, 2163L, 2164L, 2165L, 2166L, 2167L, 2168L,
2169L, 2170L, 2171L, 2172L, 2173L, 2174L, 2175L, 2176L, 2177L,
2178L, 2179L, 2180L, 2181L, 2182L, 2183L, 2184L, 2185L, 2186L,
2187L, 2188L, 2189L, 2190L, 2191L, 2192L, 2193L, 2194L, 2195L,
2196L, 2197L, 2198L, 2199L, 2200L, 2201L, 2202L, 2203L, 2204L,
2205L, 2206L, 2207L, 2208L, 2209L, 2210L, 2211L, 2212L, 2213L,
2214L, 2215L, 2216L, 2217L, 2218L, 2219L, 2220L, 2221L, 2222L,
2223L, 2224L, 2225L, 2226L, 2227L, 2228L, 2229L, 2230L, 2231L,
2232L, 2233L, 2234L, 2235L, 2236L, 2237L, 2238L, 2239L, 2240L,
2241L, 2242L, 2243L, 2244L, 2245L, 2246L, 2247L, 2248L, 2249L,
2250L), class = "data.frame")
using the vector:
timevec1 = as.vector(ggplot2:::breaks(sumsq$diffdist, "n", n=8))
I normally summarise the data using xtabs and cutusing:
bb1 = data.frame(xtabs(~ratperc +cut(diffdist, timevec1 ), dat=sumsq))
colnames(bb1) = c("rating", "range", "freq", "id")
While this solution is not idea for what I wanted it, I was able to then summarise the values for each cut using ddply.
However now I need to preserve the part_no too, but I can't seem to be able to pass more than one column to cut.
The question is, is there any way to do everything in one step? Basically get for each participant the mean of all the ratings for each cut? In other words, part_no as rows, ranges as columns and the intersection being the mean of ratings for the values that below there.
If you just want the mean rating for each part_no and interval from cut(diffdist, timevec1 ) I would just do something like this:
#Add cut variable as new column
sumsq$range <- cut(sumsq$diffdist,timevec1)
#Summarise using ddply
ddply(sumsq,.(part_no,range),summarise,val = mean(ratperc))
I didn't get if you want the mean for each participant and interval or the cumulative mean along the intervals for each participant.
If you want the normal mean you can get it with
sapply(split(sumsq, cut(sumsq$diffdist, timevec1)), function(ss)
sapply(split(ss$ratperc, ss$part_no), mean))
If you want the cumulative you can rephrase it as
t(sapply(split(sumsq, sumsq$part_no), function(ss){
sapply(timevec1[-1], function(tc) mean(ss$ratperc[ss$diffdist <= tc]))
}))
Related
Merging two files based on dates with missing values
I am trying to merge two files together based on dates: However, there are two issues: I cannot use the left join function due to one of the files having the dates set as characters, and the other one set as dates. Changing one of the files values to dates does not fix the issue as it creates a list instead Using the merge function leads to a lot of missing values, as one of my dataset does not contain data for each date jointdataset <- merge(group_df, group_tweet, by = 'date', all.x= TRUE) View(jointdataset) jointdataset <- dplyr::left_join(group_df, group_tweet) Here is how my data looks like > dput(group_tweet) structure(list(date = structure(c(18628, 18629, 18630, 18631, 18632, 18633, 18634, 18635, 18636, 18637, 18638, 18639, 18640, 18641, 18642, 18643, 18644, 18645, 18646, 18647, 18648, 18649, 18650, 18651, 18652, 18653, 18654, 18655, 18656, 18657, 18658, 18659, 18660, 18661, 18662, 18663, 18664, 18665, 18666, 18667, 18668, 18669, 18670, 18671, 18672, 18673, 18674, 18675, 18676, 18677, 18678, 18679, 18680, 18681, 18682, 18683, 18684, 18685, 18686, 18687, 18688, 18689, 18690, 18691, 18692, 18693, 18694, 18695, 18696, 18697, 18698, 18699, 18700, 18701, 18702, 18703, 18704, 18705, 18706, 18707, 18708, 18709, 18710, 18711, 18712, 18713, 18714, 18715, 18716, 18717, 18718, 18719, 18720, 18721, 18722, 18723, 18724, 18725, 18726, 18727, 18728, 18729, 18730, 18731, 18732, 18733, 18734, 18735, 18736, 18737, 18738, 18739, 18740, 18741, 18742, 18743, 18744, 18745, 18746, 18747, 18748, 18749, 18750, 18751, 18752, 18753, 18754, 18755, 18756, 18757, 18758, 18759, 18760, 18761, 18762, 18763, 18764, 18765, 18766, 18767, 18768, 18769, 18770, 18771, 18772, 18773, 18774, 18775, 18776, 18777, 18778, 18779, 18780, 18781, 18782, 18783, 18784, 18785, 18786, 18787, 18788, 18789, 18790, 18791, 18792, 18793, 18794, 18795, 18796, 18797, 18798, 18799, 18800, 18801, 18802, 18803, 18804, 18805, 18806, 18807, 18808), class = "Date"), `length(text)` = c(1324L, 1548L, 1297L, 1585L, 1636L, 1583L, 1492L, 1676L, 1745L, 1389L, 1718L, 1781L, 1858L, 1798L, 1714L, 1808L, 1315L, 1644L, 1603L, 1820L, 1770L, 1843L, 1885L, 1390L, 1763L, 1875L, 1912L, 1812L, 1764L, 2117L, 1641L, 1914L, 1963L, 2092L, 1968L, 2021L, 2023L, 1331L, 1557L, 1555L, 1904L, 2034L, 1850L, 2067L, 1507L, 1738L, 1915L, 2057L, 1931L, 1859L, 2010L, 1525L, 1835L, 1850L, 1958L, 1848L, 1929L, 2015L, 1449L, 1823L, 1796L, 1902L, 1888L, 1875L, 2078L, 1442L, 1757L, 1877L, 2104L, 1926L, 1949L, 2175L, 1604L, 2030L, 1918L, 2011L, 1978L, 1959L, 2171L, 1528L, 1936L, 1889L, 2132L, 1907L, 2173L, 2233L, 1581L, 1793L, 1986L, 2128L, 2030L, 1805L, 1954L, 1459L, 1691L, 1967L, 2049L, 1835L, 1948L, 2246L, 1581L, 1950L, 1904L, 2245L, 2053L, 1877L, 1913L, 1571L, 1932L, 2004L, 2058L, 2087L, 1989L, 2180L, 1567L, 1865L, 1995L, 2144L, 2169L, 2148L, 2318L, 1606L, 1856L, 1948L, 2036L, 1887L, 2021L, 2132L, 1390L, 1717L, 1872L, 1919L, 1867L, 1994L, 2083L, 1509L, 1786L, 1808L, 1860L, 1854L, 1813L, 2102L, 1513L, 1890L, 1877L, 2063L, 1857L, 1827L, 2059L, 1413L, 1614L, 2153L, 1859L, 1920L, 1877L, 2106L, 1458L, 1822L, 1851L, 2005L, 1984L, 2097L, 2396L, 1607L, 2106L, 2256L, 2398L, 2245L, 2239L, 2287L, 1564L, 1880L, 1991L, 2053L, 2017L, 2012L, 1998L, 1361L, 1663L, 1778L, 1987L )), row.names = c(NA, -181L), class = c("tbl_df", "tbl", "data.frame" )) dput(group_df) structure(list(date = c("01/01/2021", "01/05/2021", "01/06/2021", "01/07/2021", "01/11/2021", "01/12/2021", "01/14/2021", "01/15/2021", "01/18/2021", "01/19/2021", "01/20/2021", "01/21/2021", "01/22/2021", "01/23/2021", "01/26/2021", "01/27/2021", "01/28/2021", "01/29/2021", "01/31/2021", "02/01/2021", "02/02/2021", "02/04/2021", "02/08/2021", "02/09/2021", "02/10/2021", "02/11/2021", "02/12/2021", "02/15/2021", "02/16/2021", "02/18/2021", "02/19/2021", "02/22/2021", "02/23/2021", "02/24/2021", "02/25/2021", "02/27/2021", "03/01/2021", "03/02/2021", "03/04/2021", "03/05/2021", "03/06/2021", "03/07/2021", "03/08/2021", "03/09/2021", "03/11/2021", "03/14/2021", "03/15/2021", "03/16/2021", "03/17/2021", "03/18/2021", "03/19/2021", "03/20/2021", "03/21/2021", "03/22/2021", "03/23/2021", "03/24/2021", "03/25/2021", "03/26/2021", "03/28/2021", "03/29/2021", "03/30/2021", "03/31/2021", "04/01/2021", "04/02/2021", "04/03/2021", "04/04/2021", "04/05/2021", "04/06/2021", "04/07/2021", "04/08/2021", "04/09/2021", "04/10/2021", "04/11/2021", "04/12/2021", "04/13/2021", "04/14/2021", "04/15/2021", "04/16/2021", "04/17/2021", "04/18/2021", "04/19/2021", "04/20/2021", "04/21/2021", "04/22/2021", "04/23/2021", "04/24/2021", "04/26/2021", "04/27/2021", "04/28/2021", "04/29/2021", "04/30/2021", "05/01/2021", "05/02/2021", "05/03/2021", "05/04/2021", "05/05/2021", "05/06/2021", "05/07/2021", "05/08/2021", "05/10/2021", "05/11/2021", "05/12/2021", "05/13/2021", "05/14/2021", "05/15/2021", "05/18/2021", "05/19/2021", "05/20/2021", "05/21/2021", "05/22/2021", "05/23/2021", "05/25/2021", "05/26/2021", "05/27/2021", "05/29/2021", "05/31/2021", "06/01/2021", "06/02/2021", "06/03/2021", "06/04/2021", "06/05/2021", "06/06/2021", "06/07/2021", "06/08/2021", "06/09/2021", "06/10/2021", "06/11/2021", "06/12/2021", "06/13/2021", "06/14/2021", "06/15/2021", "06/16/2021", "06/17/2021" ), `length(category)` = c(4L, 8L, 4L, 4L, 4L, 12L, 8L, 8L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 8L, 9L, 25L, 10L, 5L, 10L, 5L, 20L, 5L, 5L, 19L, 10L, 20L, 5L, 5L, 5L, 2L, 12L, 22L, 14L, 2L, 4L, 6L, 9L, 5L, 37L, 5L, 4L, 10L, 12L, 21L, 4L, 4L, 6L, 6L, 9L, 16L, 9L, 6L, 13L, 2L, 19L, 24L, 20L, 8L, 25L, 16L, 5L, 24L, 27L, 24L, 6L, 9L, 15L, 8L, 25L, 35L, 26L, 8L, 2L, 5L, 14L, 12L, 20L, 19L, 7L, 9L, 5L, 4L, 17L, 13L, 15L, 8L, 10L, 7L, 5L, 16L, 11L, 16L, 10L, 6L, 3L, 22L, 10L, 10L, 3L, 1L, 7L, 4L, 6L, 4L, 5L, 3L, 6L, 3L, 3L, 1L, 3L, 9L, 6L, 4L, 2L, 1L, 1L, 3L, 5L, 2L, 4L, 2L, 2L, 1L, 5L, 5L, 6L, 3L), `sum(usd_pledged)` = c(50278.64, 366279.590415302, 172073.0471292, 230.537553792, 304353.5676352, 285277.861423738, 931521.92, 62322.104033708, 292739.37663744, 97895.025306156, 20538.4758468, 5716, 69712, 15248.7519561728, 1257502.99126928, 102268, 32151.762183708, 70322.17520884, 27549.00453216, 8371657.96195552, 1420782.4068818, 137818.171860595, 1175436.75496273, 1770825.83285245, 1070, 178761.8127624, 10016.918409372, 146129.2, 610608.234267955, 676175.367448825, 1274147.86429578, 45595.6660422, 1776940, 4198.748196, 17.02446963, 55272.18380506, 490750.12364435, 571800.5, 227.26420984, 619.23335154, 5942.151506976, 1098.48977709, 87300, 1879564.14902818, 57100, 3.628861728, 715993, 228885.860968739, 1005412.33040269, 32978.39955816, 1956.52590528, 5789.84841572, 508.6539266268, 192238.643979976, 278988.70418106, 32470.60072344, 10653.5543364, 333900.00289616, 2467.35065664, 698082.326436438, 581461.49769354, 170032.27513805, 24516.65281874, 11530.3738156855, 20060.6125168384, 154030.2061095, 215919.1704622, 1320696.42919177, 2000470.11990896, 1414.108082664, 12429.5108974052, 80676.567104964, 3211.42501648, 69994.39317561, 827188.797715076, 51349.427891072, 47925.216359587, 42, 28391.25545206, 6199141.75469484, 16078.9170341546, 724307.969231123, 238317.166592813, 243887.2812338, 3856.910710253, 5982.1359855268, 1986.4520326, 180186.734055936, 25818.301703542, 284175.24917946, 27486.5134227176, 51837.3569258, 218101.634171675, 543.2343820104, 299634.97422679, 9200.1639420603, 112660.244016819, 27675.2965010449, 5203.03118806, 75650.25, 327968.549088524, 1002.27102748, 37881.2795828444, 2896.1824198269, 596, 206880.064933601, 1688.14367074, 19176.1722666628, 48811.21823157, 4572.83962465, 375.36475346, 126743.686979946, 489.0998, 4042.91231235, 1343.0098244, 2286.711086, 77485.7681307, 25272.4433349128, 11630.0007860946, 377.22065991, 199.9004139, 161, 2667.93172391, 69404.71338983, 23796.67811208, 17174.64072667, 9950.0416377665, 35443.95356773, 184.603426004, 85934.0997877056, 5603.88739935, 2306.02823117, 13.0064795336), `sum(backers_count)` = c(2880L, 6588L, 3528L, 16L, 4204L, 6632L, 15404L, 1672L, 3588L, 416L, 464L, 364L, 1488L, 228L, 17124L, 2284L, 1348L, 2324L, 744L, 185822L, 35095L, 5980L, 24615L, 32525L, 40L, 4650L, 450L, 2640L, 15952L, 9275L, 16404L, 990L, 35075L, 79L, 6L, 1578L, 10705L, 9302L, 12L, 20L, 36L, 91L, 1505L, 40509L, 1890L, 4L, 9684L, 4196L, 16477L, 754L, 62L, 54L, 36L, 3787L, 3809L, 996L, 132L, 13216L, 50L, 12073L, 13826L, 4353L, 220L, 393L, 628L, 3607L, 6712L, 22403L, 30468L, 106L, 136L, 1854L, 102L, 1623L, 14638L, 1396L, 1923L, 6L, 426L, 161556L, 1020L, 6922L, 3575L, 1627L, 84L, 101L, 56L, 2291L, 450L, 2439L, 678L, 864L, 3195L, 17L, 6072L, 215L, 3119L, 1473L, 85L, 2306L, 7622L, 41L, 973L, 117L, 20L, 3127L, 45L, 424L, 819L, 84L, 12L, 3239L, 18L, 66L, 7L, 35L, 1651L, 651L, 242L, 25L, 13L, 6L, 59L, 1747L, 325L, 244L, 231L, 862L, 6L, 1819L, 74L, 66L, 4L)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -133L)) dput(group_df) structure(list(date = c("01/01/2021", "01/05/2021", "01/06/2021", "01/07/2021", "01/11/2021", "01/12/2021", "01/14/2021", "01/15/2021", "01/18/2021", "01/19/2021", "01/20/2021", "01/21/2021", "01/22/2021", "01/23/2021", "01/26/2021", "01/27/2021", "01/28/2021", "01/29/2021", "01/31/2021", "02/01/2021", "02/02/2021", "02/04/2021", "02/08/2021", "02/09/2021", "02/10/2021", "02/11/2021", "02/12/2021", "02/15/2021", "02/16/2021", "02/18/2021", "02/19/2021", "02/22/2021", "02/23/2021", "02/24/2021", "02/25/2021", "02/27/2021", "03/01/2021", "03/02/2021", "03/04/2021", "03/05/2021", "03/06/2021", "03/07/2021", "03/08/2021", "03/09/2021", "03/11/2021", "03/14/2021", "03/15/2021", "03/16/2021", "03/17/2021", "03/18/2021", "03/19/2021", "03/20/2021", "03/21/2021", "03/22/2021", "03/23/2021", "03/24/2021", "03/25/2021", "03/26/2021", "03/28/2021", "03/29/2021", "03/30/2021", "03/31/2021", "04/01/2021", "04/02/2021", "04/03/2021", "04/04/2021", "04/05/2021", "04/06/2021", "04/07/2021", "04/08/2021", "04/09/2021", "04/10/2021", "04/11/2021", "04/12/2021", "04/13/2021", "04/14/2021", "04/15/2021", "04/16/2021", "04/17/2021", "04/18/2021", "04/19/2021", "04/20/2021", "04/21/2021", "04/22/2021", "04/23/2021", "04/24/2021", "04/26/2021", "04/27/2021", "04/28/2021", "04/29/2021", "04/30/2021", "05/01/2021", "05/02/2021", "05/03/2021", "05/04/2021", "05/05/2021", "05/06/2021", "05/07/2021", "05/08/2021", "05/10/2021", "05/11/2021", "05/12/2021", "05/13/2021", "05/14/2021", "05/15/2021", "05/18/2021", "05/19/2021", "05/20/2021", "05/21/2021", "05/22/2021", "05/23/2021", "05/25/2021", "05/26/2021", "05/27/2021", "05/29/2021", "05/31/2021", "06/01/2021", "06/02/2021", "06/03/2021", "06/04/2021", "06/05/2021", "06/06/2021", "06/07/2021", "06/08/2021", "06/09/2021", "06/10/2021", "06/11/2021", "06/12/2021", "06/13/2021", "06/14/2021", "06/15/2021", "06/16/2021", "06/17/2021" ), `length(category)` = c(4L, 8L, 4L, 4L, 4L, 12L, 8L, 8L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 8L, 9L, 25L, 10L, 5L, 10L, 5L, 20L, 5L, 5L, 19L, 10L, 20L, 5L, 5L, 5L, 2L, 12L, 22L, 14L, 2L, 4L, 6L, 9L, 5L, 37L, 5L, 4L, 10L, 12L, 21L, 4L, 4L, 6L, 6L, 9L, 16L, 9L, 6L, 13L, 2L, 19L, 24L, 20L, 8L, 25L, 16L, 5L, 24L, 27L, 24L, 6L, 9L, 15L, 8L, 25L, 35L, 26L, 8L, 2L, 5L, 14L, 12L, 20L, 19L, 7L, 9L, 5L, 4L, 17L, 13L, 15L, 8L, 10L, 7L, 5L, 16L, 11L, 16L, 10L, 6L, 3L, 22L, 10L, 10L, 3L, 1L, 7L, 4L, 6L, 4L, 5L, 3L, 6L, 3L, 3L, 1L, 3L, 9L, 6L, 4L, 2L, 1L, 1L, 3L, 5L, 2L, 4L, 2L, 2L, 1L, 5L, 5L, 6L, 3L), `sum(usd_pledged)` = c(50278.64, 366279.590415302, 172073.0471292, 230.537553792, 304353.5676352, 285277.861423738, 931521.92, 62322.104033708, 292739.37663744, 97895.025306156, 20538.4758468, 5716, 69712, 15248.7519561728, 1257502.99126928, 102268, 32151.762183708, 70322.17520884, 27549.00453216, 8371657.96195552, 1420782.4068818, 137818.171860595, 1175436.75496273, 1770825.83285245, 1070, 178761.8127624, 10016.918409372, 146129.2, 610608.234267955, 676175.367448825, 1274147.86429578, 45595.6660422, 1776940, 4198.748196, 17.02446963, 55272.18380506, 490750.12364435, 571800.5, 227.26420984, 619.23335154, 5942.151506976, 1098.48977709, 87300, 1879564.14902818, 57100, 3.628861728, 715993, 228885.860968739, 1005412.33040269, 32978.39955816, 1956.52590528, 5789.84841572, 508.6539266268, 192238.643979976, 278988.70418106, 32470.60072344, 10653.5543364, 333900.00289616, 2467.35065664, 698082.326436438, 581461.49769354, 170032.27513805, 24516.65281874, 11530.3738156855, 20060.6125168384, 154030.2061095, 215919.1704622, 1320696.42919177, 2000470.11990896, 1414.108082664, 12429.5108974052, 80676.567104964, 3211.42501648, 69994.39317561, 827188.797715076, 51349.427891072, 47925.216359587, 42, 28391.25545206, 6199141.75469484, 16078.9170341546, 724307.969231123, 238317.166592813, 243887.2812338, 3856.910710253, 5982.1359855268, 1986.4520326, 180186.734055936, 25818.301703542, 284175.24917946, 27486.5134227176, 51837.3569258, 218101.634171675, 543.2343820104, 299634.97422679, 9200.1639420603, 112660.244016819, 27675.2965010449, 5203.03118806, 75650.25, 327968.549088524, 1002.27102748, 37881.2795828444, 2896.1824198269, 596, 206880.064933601, 1688.14367074, 19176.1722666628, 48811.21823157, 4572.83962465, 375.36475346, 126743.686979946, 489.0998, 4042.91231235, 1343.0098244, 2286.711086, 77485.7681307, 25272.4433349128, 11630.0007860946, 377.22065991, 199.9004139, 161, 2667.93172391, 69404.71338983, 23796.67811208, 17174.64072667, 9950.0416377665, 35443.95356773, 184.603426004, 85934.0997877056, 5603.88739935, 2306.02823117, 13.0064795336), `sum(backers_count)` = c(2880L, 6588L, 3528L, 16L, 4204L, 6632L, 15404L, 1672L, 3588L, 416L, 464L, 364L, 1488L, 228L, 17124L, 2284L, 1348L, 2324L, 744L, 185822L, 35095L, 5980L, 24615L, 32525L, 40L, 4650L, 450L, 2640L, 15952L, 9275L, 16404L, 990L, 35075L, 79L, 6L, 1578L, 10705L, 9302L, 12L, 20L, 36L, 91L, 1505L, 40509L, 1890L, 4L, 9684L, 4196L, 16477L, 754L, 62L, 54L, 36L, 3787L, 3809L, 996L, 132L, 13216L, 50L, 12073L, 13826L, 4353L, 220L, 393L, 628L, 3607L, 6712L, 22403L, 30468L, 106L, 136L, 1854L, 102L, 1623L, 14638L, 1396L, 1923L, 6L, 426L, 161556L, 1020L, 6922L, 3575L, 1627L, 84L, 101L, 56L, 2291L, 450L, 2439L, 678L, 864L, 3195L, 17L, 6072L, 215L, 3119L, 1473L, 85L, 2306L, 7622L, 41L, 973L, 117L, 20L, 3127L, 45L, 424L, 819L, 84L, 12L, 3239L, 18L, 66L, 7L, 35L, 1651L, 651L, 242L, 25L, 13L, 6L, 59L, 1747L, 325L, 244L, 231L, 862L, 6L, 1819L, 74L, 66L, 4L)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -133L)) My final objective is to get a dataset, where i can get for each date the data, including for the days where there is missing data in one of the data sets
I assume your key problem is changing eg 01/15/2022 to a date. You can easily use the package lubridates mdy() function for this (install.packages('lubridate'). *adjusted from your comment. You can run: library(dplyr) library(lubridate) group_df %>% mutate(date = mdy(date)) %>% full_join( group_tweet ) %>% arrange(date) Output is: Joining, by = "date" # A tibble: 181 × 5 date `length(category)` `sum(usd_pledged)` `sum(backers_count)` `length(text)` <date> <int> <dbl> <int> <int> 1 2021-01-01 4 50279. 2880 1324 2 2021-01-02 NA NA NA 1548 3 2021-01-03 NA NA NA 1297 4 2021-01-04 NA NA NA 1585 5 2021-01-05 8 366280. 6588 1636 6 2021-01-06 4 172073. 3528 1583 7 2021-01-07 4 231. 16 1492 8 2021-01-08 NA NA NA 1676 9 2021-01-09 NA NA NA 1745 10 2021-01-10 NA NA NA 1389 # … with 171 more rows
How can I add a legend to this graph?
I have a graph that I would like to add a legend to: So far I have been able to either add a legend which defaults to its own colours, or one which changes the colours to a gradient fill which isn't what I want. What am I doing wrong and how can I fix it? Plot code: ggplot(df) + geom_line(aes(date, actual, group = 1), colour = "forestgreen") + geom_line(aes(date, plan, group = 1), colour = "red") + geom_smooth(aes(date, difference), method = "auto", se = FALSE, linetype = "dashed") + scale_x_date(date_breaks = "4 days" , date_labels = "%d-%b-%y") + facet_grid(sector ~ ., scales = "free") dput: structure(list(date = structure(c(17959, 17959, 17959, 17959, 17959, 17960, 17960, 17960, 17960, 17960, 17961, 17961, 17961, 17961, 17961, 17962, 17962, 17962, 17962, 17962, 17963, 17963, 17963, 17963, 17963, 17964, 17964, 17964, 17964, 17964, 17965, 17965, 17965, 17965, 17965, 17966, 17966, 17966, 17966, 17966, 17967, 17967, 17967, 17967, 17967, 17968, 17968, 17968, 17968, 17968, 17969, 17969, 17969, 17969, 17969, 17970, 17970, 17970, 17970, 17970, 17971, 17971, 17971, 17971, 17971, 17972, 17972, 17972, 17972, 17972, 17973, 17973, 17973, 17973, 17973, 17974, 17974, 17974, 17974, 17974, 17975, 17975, 17975, 17975, 17975, 17976, 17976, 17976, 17976, 17976, 17977, 17977, 17977, 17977, 17977, 17978, 17978, 17978, 17978, 17978, 17979, 17979, 17979, 17979, 17979, 17980, 17980, 17980, 17980, 17980, 17981, 17981, 17981, 17981, 17981, 17982, 17982, 17982, 17982, 17982, 17983, 17983, 17983, 17983, 17983, 17984, 17984, 17984, 17984, 17984, 17985, 17985, 17985, 17985, 17985, 17986, 17986, 17986, 17986, 17986, 17987, 17987, 17987, 17987, 17987, 17988, 17988, 17988, 17988, 17988, 17989, 17989, 17989, 17989, 17989, 17990, 17990, 17990, 17990, 17990, 17991, 17991, 17991, 17991, 17991, 17992, 17992, 17992, 17992, 17992, 17993, 17993, 17993, 17993, 17993 ), class = "Date"), sector = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), .Label = c("ADVANCE CLINICIAN", "CALL HANDLERS", "CLINICIANS", "GP", "PHARMACIST"), class = "factor"), actual = c(16L, 232L, 104L, 40L, 12L, 23L, 231L, 90L, 47L, 12L, 34L, 245L, 109L, 61L, 0L, 32L, 226L, 99L, 50L, 0L, 25L, 247L, 103L, 58L, 7L, 84L, 362L, 89L, 57L, 8L, 50L, 333L, 86L, 44L, 11L, 14L, 276L, 71L, 68L, 7L, 24L, 263L, 93L, 62L, 12L, 42L, 241L, 92L, 42L, 13L, 42L, 242L, 106L, 60L, 8L, 50L, 262L, 101L, 58L, 8L, 38L, 340L, 80L, 42L, 0L, 32L, 312L, 73L, 39L, 8L, 14L, 219L, 81L, 54L, 15L, 19L, 239L, 100L, 50L, 20L, 15L, 245L, 104L, 58L, 13L, 38L, 233L, 90L, 57L, 8L, 50L, 236L, 94L, 41L, 7L, 78L, 370L, 106L, 61L, 8L, 34L, 328L, 91L, 45L, 8L, 16L, 247L, 54L, 57L, 20L, 19L, 263L, 93L, 43L, 15L, 26L, 231L, 88L, 58L, 13L, 50L, 234L, 87L, 61L, 8L, 68L, 245L, 113L, 50L, 15L, 68L, 352L, 89L, 38L, 8L, 22L, 288L, 98L, 18L, 11L, 13L, 201L, 34L, 40L, 8L, 12L, 208L, 41L, 45L, 8L, 5L, 215L, 48L, 45L, 0L, 53L, 210L, 45L, 55L, 0L, 20L, 220L, 71L, 23L, 8L, 12L, 349L, 80L, 54L, 8L, 2L, 287L, 52L, 35L, 0L), plan = c(43L, 291L, 28L, 32L, 11L, 37L, 262L, 25L, 32L, 11L, 39L, 260L, 22L, 32L, 11L, 34L, 266L, 90L, 32L, 11L, 39L, 269L, 93L, 32L, 11L, 66L, 422L, 152L, 61L, 14L, 54L, 373L, 133L, 53L, 14L, 43L, 291L, 106L, 32L, 11L, 37L, 262L, 90L, 32L, 11L, 39L, 260L, 94L, 32L, 11L, 34L, 266L, 90L, 32L, 11L, 39L, 269L, 93L, 32L, 11L, 66L, 422L, 152L, 61L, 14L, 54L, 373L, 133L, 53L, 14L, 43L, 291L, 106L, 32L, 11L, 37L, 262L, 90L, 32L, 11L, 39L, 260L, 94L, 32L, 11L, 34L, 266L, 90L, 32L, 11L, 39L, 269L, 93L, 32L, 11L, 66L, 422L, 152L, 61L, 14L, 54L, 373L, 133L, 53L, 14L, 43L, 291L, 106L, 32L, 11L, 37L, 262L, 90L, 32L, 11L, 39L, 260L, 94L, 32L, 11L, 34L, 266L, 90L, 32L, 11L, 39L, 269L, 93L, 32L, 11L, 66L, 422L, 152L, 61L, 14L, 54L, 373L, 133L, 53L, 14L, 43L, 283L, 73L, 32L, 11L, 37L, 283L, 99L, 32L, 11L, 39L, 264L, 88L, 32L, 11L, 34L, 260L, 90L, 32L, 11L, 39L, 275L, 98L, 32L, 11L, 66L, 424L, 156L, 61L, 14L, 54L, 360L, 130L, 53L, 14L), difference = c(-27L, -59L, 76L, 8L, 1L, -14L, -31L, 65L, 15L, 1L, -5L, -15L, 87L, 29L, -11L, -2L, -40L, 9L, 18L, -11L, -14L, -22L, 10L, 26L, -4L, 18L, -60L, -63L, -4L, -6L, -4L, -40L, -47L, -9L, -3L, -29L, -15L, -35L, 36L, -4L, -13L, 1L, 3L, 30L, 1L, 3L, -19L, -2L, 10L, 2L, 8L, -24L, 16L, 28L, -3L, 11L, -7L, 8L, 26L, -3L, -28L, -82L, -72L, -19L, -14L, -22L, -61L, -60L, -14L, -6L, -29L, -72L, -25L, 22L, 4L, -18L, -23L, 10L, 18L, 9L, -24L, -15L, 10L, 26L, 2L, 4L, -33L, 0L, 25L, -3L, 11L, -33L, 1L, 9L, -4L, 12L, -52L, -46L, 0L, -6L, -20L, -45L, -42L, -8L, -6L, -27L, -44L, -52L, 25L, 9L, -18L, 1L, 3L, 11L, 4L, -13L, -29L, -6L, 26L, 2L, 16L, -32L, -3L, 29L, -3L, 29L, -24L, 20L, 18L, 4L, 2L, -70L, -63L, -23L, -6L, -32L, -85L, -35L, -35L, -3L, -30L, -82L, -39L, 8L, -3L, -25L, -75L, -58L, 13L, -3L, -34L, -49L, -40L, 13L, -11L, 19L, -50L, -45L, 23L, -11L, -19L, -55L, -27L, -9L, -3L, -54L, -75L, -76L, -7L, -6L, -52L, -73L, -78L, -18L, -14L)), row.names = c(NA, -175L), class = c("tbl_df", "tbl", "data.frame"))
Place the colour argument in aes and just write the label for it there. You can rename the title with +labs(colour="Legend Title"), and manipulate the colours with scale_fill_manual(values) ggplot(df) + geom_line(aes(date, actual, group = 1,colour = "actual") ) + geom_line(aes(date, plan, group = 1,colour ="plan")) + geom_smooth(aes(date, difference,colour="difference"), method = "auto", se = FALSE, linetype = "dashed") + scale_x_date(date_breaks = "4 days" , date_labels = "%d-%b-%y")+ facet_grid(sector ~ ., scales = "free")+ labs(colour="Method")+ scale_colour_manual(values=c("forestgreen","red","blue")) Hope this is helpful!
Count UNIQUE points within each grid box
I have the following data: EDIT: With smaller sample data dat <- structure(list(SN = c(198305L, 198305L, 198305L, 198305L, 198305L,198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198305L, 198306L, 198306L, 198306L, 198306L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198308L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L, 198310L), CY = c(5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L), Year = c(1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L), Month = c(8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L ), Day = c(9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 14L, 14L, 14L, 14L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 21L, 21L, 22L, 22L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 25L, 25L, 25L, 25L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L), Hour = c(0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L, 0L, 6L, 12L, 18L), Lat = c(17.8, 18.1, 18.7, 18.9, 19.2, 19.5, 19.9, 20.1, 20.6, 21.2, 21.6, 22, 22.5, 22.9, 23.4, 23.9, 24.6, 24.9, 25.4, 26.1, 26.6, 27.2, 27.6, 28.1, 28.5, 29.1, 29.5, 30, 31.1, 31.8, 32.7, 33.8, 34.6, 35.1, 35.6, 19.8, 19.9, 19.9, 20.2, 15.9, 16.1, 16.3, 16.5, 16.9, 17.4, 18, 18.7, 19.3, 20, 23.8, 24.2, 24.9, 25.4, 25.8, 25.5, 25.1, 25.3, 25.8, 26.2, 26.5, 27.1, 27.9, 29.1, 10.3, 10.2, 9, 9.2, 9.2, 9.5, 10, 10.5, 10.9, 11.3, 12.3, 13, 13.7, 14.4, 15, 15.9, 16.8, 17.2, 17.8, 18.3, 18.7, 19, 19.3, 19.5, 19.7, 20), Lon = c(130.8, 130.7, 130.3, 130.4, 130.4, 130.4, 130.5, 130.5, 130.7, 130.8, 130.7, 130.6, 130.7, 130.8, 131.2, 131.5, 131.8, 132.2, 132.6, 133, 133.3, 133.5, 133.5, 133.5, 133.6, 134.1, 134.3, 134.8, 135.1, 135.8, 136.5, 137, 137.3, 138.1, 139.4, 121.5, 122.7, 124.4, 126.2, 133.8, 133.2, 132.8, 132.4, 132.2, 132.5, 133, 133.7, 134.7, 135.6, 140.1, 141.6, 142.6, 143.1, 143.5, 144, 144.3, 144.7, 144.7, 144.1, 143.4, 142.8, 141.8, 141.3, 151.2, 149.2, 143.4, 141.8, 140.2, 138.9, 137.5, 136, 134.4, 133, 131.7, 130.7, 129.6, 128.8, 128, 126.9, 125.8, 125.1, 124.1, 123.2, 122.2, 121.2, 120.2, 119.2, 118.3, 117.5), VMax = c(145L, 135L, 125L, 120L, 120L, 120L, 115L, 110L, 110L, 115L, 120L, 120L, 120L, 120L, 125L, 120L, 115L, 110L, 105L, 105L, 110L, 100L, 100L, 95L, 90L, 85L, 85L, 80L, 75L, 70L, 70L, 70L, 60L, 55L, 45L, 35L, 40L, 45L, 40L, 35L, 40L, 45L, 50L, 55L, 50L, 45L, 40L, 35L, 35L, 35L, 45L, 50L, 50L, 45L, 40L, 40L, 45L, 50L, 50L, 50L, 45L, 40L, 35L, 35L, 35L, 35L, 40L, 45L, 50L, 55L, 60L, 65L, 70L, 75L, 85L, 90L, 95L, 95L, 95L, 95L, 100L, 120L, 125L, 120L, 100L, 90L, 85L, 85L, 80L), Cat = structure(c(5L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 4L, 4L, 4L, 3L, 2L, 2L, 2L, 1L), .Label = c("Cat1", "Cat2", "Cat3", "Cat4", "Cat5", "TS"), class = "factor")), row.names = c(243L, 244L, 245L, 246L, 247L, 248L, 249L, 250L, 251L, 252L, 253L, 254L, 255L, 256L, 257L, 258L, 259L, 260L, 261L, 262L, 263L, 264L, 265L, 266L, 267L, 268L, 269L, 270L, 271L, 272L, 273L, 274L, 275L, 276L, 277L, 278L, 279L, 280L, 281L, 282L, 283L, 284L, 285L, 286L, 287L, 288L, 289L, 290L, 291L, 292L, 293L, 294L, 295L, 296L, 297L, 298L, 299L, 300L, 301L, 302L, 303L, 304L, 305L, 927L, 928L, 929L, 930L, 931L, 932L, 933L, 934L, 935L, 936L, 937L, 938L, 939L, 940L, 941L, 942L, 943L, 944L, 945L, 946L, 947L, 948L, 949L, 950L, 951L, 952L ), class = "data.frame") Each lat-lon pair has a unique identifier, the SN column. I created a grid and I want to count the number of unique lat-lon pairs within each grid. Here's my script: latmin=0 latmax=50 lonmin=60 lonmax=180 dlat=2.5 dlon=2.5 latint=dlat*0.5 lonint=dlon*0.5 ## derive center lat and lon points x.Lon<-seq((lonmin+lonint),(lonmax-lonint),lonint) y.Lat<-seq((latmin+latint),(latmax-latint),latint) df2<-as.data.frame(expand.grid(x.Lon=x.Lon,y.Lat=y.Lat)) df2$count<-"0" library(data.table) library(expss) setDT(dat) dummy<-matrix(ncol=1,nrow=nrow(df2)) for (i in 1:nrow(df2)){ df_bounds<-data.frame(north=(df2[i,]$y.Lat+latint),south=(df2[i,]$y.Lat-latint),west=(df2[i,]$x.Lon-lonint),east=(df2[i,]$x.Lon+lonint)) dat[,inBounds := Lat >= (df2[i,]$y.Lat-latint) & Lat <= (df2[i,]$y.Lat+latint) & Lon >= (df2[i,]$x.Lon-lonint) & Lon >= (df2[i,]$x.Lon+lonint)] dat1<-dat[SN %in% dat[inBounds == TRUE, unique(SN)],passesThroughBox := T] #dat2<-dat[is.na(passesThroughBox),passesThroughBox := F] #dat3<-dat1[which(passesThroughBox == TRUE),] dummy[i,]<-count_if("TRUE",dat1$passesThroughBox) } PROBLEMS/QUESTIONS The dummy matrix only contains 0 values. I think I am not counting the unique points correctly. EXPECTED OUTPUTS The df2 data frame with an additional column containing the unique counts. A gridded plot of df2, where the color corresponds to the counts. Any suggestions on how to do this in R? I'll appreciate any help.
Given the observations data-frame dat and grid data-frame df2. For each observation in dat find the nearest grid center in df2 to obtain the grid it belongs to. This is based on assumption that an observation belongs to its nearest grid center. Also, For each SN only the first entry reported is taken as the unique observation. df2<-as.data.frame(expand.grid(x.Lon=x.Lon,y.Lat=y.Lat)) # grid box centers df2$count<- 0L # keeping count as integer # function to calculate distance between two points dist <- function(x, y) {diff <- (y - x) ; sqrt(sum(diff^2))} # Filtering only the unique observation dat <- dat[!duplicated(dat$SN), ] # Finding closest grid center for every observation in dat closest_grid <- apply(dat[,c('Lon','Lat')],1, function(x){ dist_grid <- apply(df2[,c('x.Lon','y.Lat')], 1, function(y) dist(x,y)) return(which.min(dist_grid)) }) # Summarizing no of of counts for each grid center with non zero counts df2[names(table(closest_grid)),'count'] <- as.integer(table(closest_grid)) df2[names(table(closest_grid)),] # the non-zero counts # x.Lon y.Lat count #738 151.25 10.00 1 #1199 133.75 16.25 1 #1292 131.25 17.50 1 #1474 121.25 20.00 1 Use ggplot2 to plot the the count heat-map at grid centers: library(ggplot2) # fill = counts data ggplot(data = df2, aes(x = x.Lon, y = y.Lat)) + geom_tile(aes(fill = count)) The below plot is for your full data-set:
Extracting overlaping pairs of rows from df with two columns
I would like to find out which pairs overlap between these two tables: > dput(data1) structure(list(Name.x = c("MDH1", "MDH1", "IDH2", "IDH2", "IDH2", "IDH2", "IDH2", "IDH2", "IDH2", "SCOALB", "SCOALB", "CSY4", "CSY4", "CSY4", "CSY4", "CSY4", "FUM1", "FUM1", "IDH6", "IDH6", "IDH6", "ODC1-1", "ODC1-1", "ODC1-1", "ODC1-1", "ODC1-1", "ODC2-1", "ODC2-1", "ODC2-1", "ACO2", "IDH1", "IDH1", "IDH1", "IDH1", "ODC2-2"), Name.y = c("SCOALB", "SCOALA-1", "CSY4", "IDH6", "ODC1-1", "ODC2-1", "IDH1", "ODC2-2", "ODC1-2", "SCOALA-1", "SCOALA-2", "IDH6", "SDH2-1", "IDH1", "IDH5", "ICDH", "ODC1-1", "ODC1-2", "ACO2", "IDH1", "IDH5", "ODC2-1", "IDH1", "IDH5", "ODC2-2", "ODC1-2", "IDH1", "ODC2-2", "ODC1-2", "IDH1", "IDH5", "SCOALA-2", "ODC2-2", "ODC1-2", "ODC1-2")), .Names = c("Name.x", "Name.y" ), class = "data.frame", row.names = c(NA, -35L)) > dput(data2) structure(list(Protein1 = structure(c(3L, 7L, 18L, 19L, 7L, 19L, 6L, 18L, 6L, 18L, 18L, 19L, 9L, 8L, 19L, 18L, 9L, 7L, 18L, 12L, 8L, 19L, 5L, 29L, 12L, 29L, 12L, 18L, 7L, 17L, 6L, 5L, 9L, 19L, 12L, 3L, 19L, 16L, 18L, 17L, 16L, 17L, 9L, 29L, 12L, 7L, 29L, 18L, 16L, 18L, 29L, 8L, 17L, 16L, 17L, 12L, 6L, 8L, 17L, 29L, 9L, 17L, 29L, 19L, 8L, 17L, 29L, 9L, 9L, 16L, 29L, 29L, 19L, 19L, 19L, 29L, 12L, 19L, 17L, 29L, 17L, 16L, 16L, 19L, 16L, 4L, 1L, 5L, 17L, 9L, 18L, 18L, 6L, 4L, 8L, 16L, 16L, 29L, 7L, 12L, 8L, 4L, 29L, 12L, 5L), .Label = c("ACO2", "ACO3", "CSY4", "FUM1", "ICDH", "IDH1", "IDH2", "IDH5", "IDH6", "LPD1", "LPD2", "MDH1", "MDH2", "ME1", "ME2", "ODC1-1", "ODC1-2", "ODC2-1", "ODC2-2", "PDC1a-1", "PDC1a-2", "PDC1b", "PDC2-1", "PDC2-2", "SCoALa-1", "SCoALa-2", "SCoALb", "SDH1-1", "SDH2-1", "SDH2-2", "SDH2-3", "SDH3-1", "SDH4", "SDH5", "SDH6", "SDH7a", "SDH7b", "SDH8"), class = "factor"), Protein2 = structure(c(1L, 6L, 7L, 17L, 1L, 16L, 3L, 9L, 1L, 5L, 17L, 9L, 8L, 7L, 18L, 18L, 5L, 3L, 16L, 3L, 5L, 8L, 4L, 7L, 5L, 3L, 6L, 6L, 5L, 3L, 5L, 3L, 3L, 6L, 7L, 3L, 7L, 9L, 1L, 8L, 5L, 16L, 7L, 6L, 4L, 7L, 4L, 3L, 3L, 12L, 1L, 1L, 9L, 7L, 7L, 9L, 6L, 6L, 5L, 8L, 1L, 17L, 29L, 3L, 8L, 6L, 9L, 9L, 6L, 12L, 5L, 19L, 12L, 5L, 1L, 16L, 1L, 19L, 4L, 18L, 12L, 1L, 4L, 4L, 6L, 3L, 1L, 1L, 1L, 4L, 4L, 8L, 4L, 1L, 3L, 8L, 16L, 12L, 4L, 12L, 4L, 4L, 17L, 8L, 5L), .Label = c("ACO2", "ACO3", "CSY4", "FUM1", "ICDH", "IDH1", "IDH2", "IDH5", "IDH6", "LPD1", "LPD2", "MDH1", "MDH2", "ME1", "ME2", "ODC1-1", "ODC1-2", "ODC2-1", "ODC2-2", "PDC1a-1", "PDC1a-2", "PDC1b", "PDC2-1", "PDC2-2", "SCoALa-1", "SCoALa-2", "SCoALb", "SDH1-1", "SDH2-1", "SDH2-2", "SDH2-3", "SDH3-1", "SDH4", "SDH5", "SDH6", "SDH7a", "SDH7b", "SDH8"), class = "factor")), .Names = c("Protein1", "Protein2"), class = "data.frame", row.names = c(1L, 4L, 6L, 12L, 22L, 25L, 28L, 33L, 44L, 48L, 51L, 52L, 53L, 60L, 68L, 70L, 72L, 76L, 86L, 109L, 110L, 119L, 133L, 144L, 146L, 158L, 170L, 197L, 202L, 206L, 211L, 213L, 226L, 227L, 237L, 271L, 272L, 286L, 290L, 297L, 304L, 305L, 306L, 319L, 323L, 327L, 347L, 348L, 351L, 357L, 370L, 372L, 373L, 378L, 379L, 392L, 406L, 410L, 414L, 417L, 419L, 437L, 442L, 445L, 448L, 455L, 457L, 462L, 471L, 479L, 482L, 483L, 488L, 503L, 509L, 522L, 536L, 563L, 618L, 620L, 623L, 628L, 630L, 644L, 647L, 666L, 668L, 673L, 676L, 678L, 679L, 690L, 691L, 694L, 698L, 703L, 709L, 714L, 715L, 722L, 723L, 724L, 727L, 739L, 740L)) In each of df there are two columns which store strings. Strings overlap between table. However, the order between pairs might be different. One string from the pair might be find in first column of data1 and in second column in data2. How to find what pairs and how many of them overlap between datasets ?
> data1$combine = as.character(interaction(data1$Name.x, data1$Name.y)) > data2$combine = as.character(interaction(data2$Protein1, data2$Protein2)) > > dat.overlap = data1[complete.cases(match(data2$combine, data1$combine)),] > dat.overlap Name.x Name.y combine 2 MDH1 SCOALA-1 MDH1.SCOALA-1 4 IDH2 IDH6 IDH2.IDH6 11 SCOALB SCOALA-2 SCOALB.SCOALA-2 13 CSY4 SDH2-1 CSY4.SDH2-1 18 FUM1 ODC1-2 FUM1.ODC1-2 28 ODC2-1 ODC2-2 ODC2-1.ODC2-2 data1[complete.cases(match(data1$combine, data2$combine)),] Name.x Name.y combine 3 IDH2 CSY4 IDH2.CSY4 7 IDH2 IDH1 IDH2.IDH1 19 IDH6 ACO2 IDH6.ACO2 20 IDH6 IDH1 IDH6.IDH1 21 IDH6 IDH5 IDH6.IDH5 23 ODC1-1 IDH1 ODC1-1.IDH1 24 ODC1-1 IDH5 ODC1-1.IDH5 27 ODC2-1 IDH1 ODC2-1.IDH1 29 ODC2-1 ODC1-2 ODC2-1.ODC1-2 35 ODC2-2 ODC1-2 ODC2-2.ODC1-2
Sort row-wise and make a key by pasting, then merge: data1$key <- apply(data1, 1, function(i) paste(sort(i), collapse = "_")) data2$key <- apply(data2, 1, function(i) paste(sort(i), collapse = "_")) res <- merge(data1, data2, by = "key") head(res) # key Name.x Name.y Protein1 Protein2 # 1 ACO2_IDH1 ACO2 IDH1 IDH1 ACO2 # 2 ACO2_IDH6 IDH6 ACO2 IDH6 ACO2 # 3 CSY4_ICDH CSY4 ICDH ICDH CSY4 # 4 CSY4_IDH1 CSY4 IDH1 IDH1 CSY4 # 5 CSY4_IDH2 IDH2 CSY4 IDH2 CSY4 # 6 CSY4_IDH5 CSY4 IDH5 IDH5 CSY4
Error while storing ggplots in list. Impossible to plot multiple ggplot, but possible to plot them separately
I'm currently working on the effects of environmental variables on the toxicity of a shellfish. This toxicity happens only on certain years. I would like to compare time series of 15 different environmental variables between toxic years and non toxic years. My data or on 10 years and 6 locations. I would like to have 1 window / site, each window containing 10 ggplots representing the 10 annual time series of one parameter here are the data i give for a reproducible example, on one location, for one parameter (Temperature): (corrected to be reproducible) structure(list(Date = structure(c(12065, 12065, 12079, 12079, 12088, 12095, 12095, 12104, 12115, 12115, 12123, 12123, 12130, 12130, 12135, 12137, 12137, 12142, 12146, 12146, 12149, 12150, 12150, 12156, 12157, 12157, 12164, 12164, 12165, 12170, 12177, 12177, 12177, 12184, 12185, 12185, 12191, 12192, 12192, 12198, 12199, 12199, 12205, 12206, 12206, 12213, 12215, 12215, 12219, 12219, 12219, 12226, 12233, 12235, 12235, 12240, 12240, 12240, 12240, 12240, 12240, 12248, 12248, 12248, 12254, 12255, 12255, 12261, 12263, 12263, 12268, 12268, 12268, 12275, 12275, 12275, 12282, 12283, 12283, 12289, 12291, 12291, 12296, 12297, 12297, 12303, 12305, 12305, 12311, 12311, 12318, 12318, 12326, 12331, 12338, 12352, 12368, 12381, 12395, 12403, 12424, 12436, 12452, 12464, 12478, 12495, 12507, 12522, 12528, 12534, 12541, 12548, 12562, 12571, 12571, 12576, 12576, 12583, 12583, 12591, 12598, 12613, 12620, 12625, 12633, 12639, 12646, 12653, 12661, 12667, 12676, 12682, 12690, 12696, 12702, 12709, 12716, 12724, 12730, 12744, 12758, 12772, 12795, 12800, 12814, 12828, 12843, 12856, 12871, 12877, 12884, 12898, 12905, 12912, 12926, 12933, 12940, 12954, 12954, 12961, 12961, 12968, 12968, 12982, 12982, 13011, 13011, 13024, 13024, 13038, 13052, 13052, 13067, 13083, 13094, 13111, 13122, 13136, 13151, 13166, 13178, 13192, 13206, 13221, 13236, 13248, 13262, 13270, 13278, 13292, 13298, 13305, 13318, 13318, 13326, 13332, 13332, 13333, 13339, 13346, 13346, 13377, 13390, 13402, 13432, 13466, 13529, 13542, 13585, 13599, 13614, 13626, 13643, 13655, 13669, 13675, 13683, 13698, 13710, 13725, 13731, 13741, 13754, 13760, 13767, 13781, 13789, 13795, 13809, 13823, 13838, 13851, 13867, 13901, 13901, 13907, 13921, 13936, 13936, 13957, 13963, 13963, 13978, 13992, 13992, 14005, 14020, 14020, 14036, 14036, 14041, 14047, 14047, 14047, 14047, 14047, 14053, 14054, 14061, 14061, 14069, 14076, 14076, 14076, 14076, 14077, 14082, 14089, 14089, 14105, 14105, 14105, 14105, 14118, 14118, 14131, 14131, 14145, 14145, 14152, 14160, 14166, 14173, 14180, 14188, 14202, 14216, 14230, 14258, 14271, 14287, 14299, 14312, 14327, 14340, 14354, 14368, 14375, 14382, 14397, 14411, 14411, 14425, 14425, 14440, 14440, 14447, 14453, 14453, 14467, 14467, 14474, 14481, 14481, 14488, 14494, 14502, 14509, 14509, 14516, 14523, 14539, 14565, 14579, 14593, 14607, 14635, 14649, 14663, 14683, 14700, 14706, 14714, 14719, 14727, 14736, 14749, 14763, 14763, 14777, 14777, 14791, 14819, 14819, 14824, 14832, 14832, 14845, 14845, 14861, 14861, 14873, 14873, 14888, 14902, 14929, 14985, 14999, 15015, 15029, 15043, 15057, 15071, 15085, 15097, 15111, 15125, 15141, 15141, 15153, 15153, 15167, 15167, 15181, 15181, 15195, 15195, 15209, 15209, 15223, 15237, 15237, 15251, 15265, 15281, 15293, 15307, 15321, 15335, 15349, 15377, 15391, 15405, 15419, 15433, 15447, 15457, 15463, 15474, 15491, 15503, 15503, 15517, 15517, 15523, 15533, 15545, 15545, 15559, 15559, 15573, 15573, 15589, 15589, 15601, 15601, 15615, 15629, 15643, 15657, 15671, 15685, 15702), class = "Date"), Annee = structure(c(9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L), .Label = c("1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013"), class = "factor"), Mois = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 12L, 12L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 12L, 12L, 1L, 1L, 1L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 10L, 10L, 11L, 11L, 12L, 12L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 9L, 10L, 11L, 1L, 1L, 3L, 3L, 4L, 4L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 9L, 9L, 9L, 10L, 10L, 10L, 11L, 11L, 12L, 12L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 12L, 12L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 11L, 12L, 12L, 12L, 1L, 2L, 2L, 3L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 10L, 10L, 11L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 10L, 10L, 11L, 11L, 11L, 12L, 12L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 11L, 11L, 12L, 12L), .Label = c("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" ), class = "factor"), Jourannee = structure(c(12L, 12L, 26L, 26L, 35L, 42L, 42L, 51L, 62L, 62L, 70L, 70L, 77L, 77L, 82L, 84L, 84L, 89L, 93L, 93L, 96L, 97L, 97L, 103L, 104L, 104L, 111L, 111L, 112L, 117L, 124L, 124L, 124L, 131L, 132L, 132L, 138L, 139L, 139L, 145L, 146L, 146L, 152L, 153L, 153L, 160L, 162L, 162L, 166L, 166L, 166L, 173L, 180L, 182L, 182L, 187L, 187L, 187L, 187L, 187L, 187L, 195L, 195L, 195L, 201L, 202L, 202L, 208L, 210L, 210L, 215L, 215L, 215L, 222L, 222L, 222L, 229L, 230L, 230L, 236L, 238L, 238L, 243L, 244L, 244L, 250L, 252L, 252L, 258L, 258L, 265L, 265L, 273L, 278L, 285L, 299L, 314L, 327L, 341L, 349L, 6L, 18L, 34L, 46L, 60L, 77L, 89L, 104L, 110L, 116L, 123L, 130L, 144L, 153L, 153L, 158L, 158L, 165L, 165L, 173L, 180L, 195L, 202L, 207L, 215L, 221L, 228L, 235L, 243L, 249L, 258L, 264L, 272L, 278L, 284L, 291L, 298L, 306L, 312L, 325L, 339L, 353L, 11L, 16L, 30L, 44L, 59L, 72L, 87L, 93L, 100L, 114L, 121L, 128L, 142L, 149L, 156L, 170L, 170L, 177L, 177L, 184L, 184L, 198L, 198L, 227L, 227L, 240L, 240L, 254L, 268L, 268L, 283L, 299L, 310L, 326L, 337L, 351L, 2L, 17L, 29L, 43L, 57L, 72L, 87L, 99L, 113L, 121L, 129L, 143L, 149L, 156L, 169L, 169L, 177L, 183L, 183L, 184L, 190L, 197L, 197L, 228L, 241L, 253L, 283L, 316L, 15L, 28L, 71L, 85L, 100L, 112L, 129L, 141L, 155L, 161L, 169L, 184L, 196L, 211L, 217L, 227L, 240L, 246L, 253L, 267L, 275L, 281L, 295L, 309L, 323L, 336L, 352L, 22L, 22L, 28L, 42L, 57L, 57L, 78L, 84L, 84L, 99L, 113L, 113L, 126L, 141L, 141L, 157L, 157L, 162L, 168L, 168L, 168L, 168L, 168L, 174L, 175L, 182L, 182L, 190L, 197L, 197L, 197L, 197L, 198L, 203L, 210L, 210L, 226L, 226L, 226L, 226L, 239L, 239L, 252L, 252L, 266L, 266L, 273L, 281L, 287L, 294L, 301L, 309L, 322L, 336L, 350L, 13L, 26L, 42L, 54L, 67L, 82L, 95L, 109L, 123L, 130L, 137L, 152L, 166L, 166L, 180L, 180L, 195L, 195L, 202L, 208L, 208L, 222L, 222L, 229L, 236L, 236L, 243L, 249L, 257L, 264L, 264L, 271L, 278L, 294L, 319L, 333L, 347L, 360L, 25L, 39L, 53L, 73L, 90L, 96L, 104L, 109L, 117L, 126L, 139L, 153L, 153L, 167L, 167L, 181L, 209L, 209L, 214L, 222L, 222L, 235L, 235L, 251L, 251L, 263L, 263L, 278L, 292L, 318L, 10L, 24L, 40L, 54L, 68L, 82L, 96L, 110L, 122L, 136L, 150L, 166L, 166L, 178L, 178L, 192L, 192L, 206L, 206L, 220L, 220L, 234L, 234L, 248L, 262L, 262L, 276L, 290L, 306L, 317L, 331L, 345L, 358L, 9L, 37L, 51L, 65L, 79L, 93L, 107L, 117L, 123L, 134L, 151L, 163L, 163L, 177L, 177L, 183L, 193L, 205L, 205L, 219L, 219L, 233L, 233L, 249L, 249L, 261L, 261L, 275L, 289L, 303L, 316L, 330L, 344L, 360L), .Label = c("002", "003", "004", "005", "006", "007", "008", "009", "010", "011", "012", "013", "014", "015", "016", "017", "018", "019", "020", "021", "022", "023", "024", "025", "026", "027", "028", "029", "030", "031", "032", "033", "034", "035", "036", "037", "038", "039", "040", "041", "042", "043", "044", "045", "046", "047", "048", "049", "050", "051", "052", "053", "054", "055", "056", "057", "058", "059", "060", "061", "062", "063", "064", "065", "066", "067", "068", "069", "070", "071", "072", "073", "074", "075", "076", "077", "078", "079", "080", "081", "082", "083", "084", "085", "086", "087", "088", "089", "090", "091", "092", "093", "094", "095", "096", "097", "098", "099", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "140", "141", "142", "143", "144", "145", "146", "147", "148", "149", "150", "151", "152", "153", "154", "155", "156", "157", "158", "159", "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175", "176", "177", "178", "179", "180", "181", "182", "183", "184", "185", "186", "187", "188", "189", "190", "191", "192", "193", "194", "195", "196", "197", "198", "199", "200", "201", "202", "203", "204", "205", "206", "207", "208", "209", "210", "211", "212", "213", "214", "215", "216", "217", "218", "219", "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", "230", "231", "232", "233", "234", "235", "236", "237", "238", "239", "240", "241", "242", "243", "244", "245", "246", "247", "248", "249", "250", "251", "252", "253", "254", "255", "256", "257", "258", "259", "260", "261", "262", "263", "264", "265", "266", "267", "268", "269", "270", "271", "272", "273", "274", "275", "276", "277", "278", "279", "280", "281", "282", "283", "284", "285", "286", "287", "288", "289", "290", "291", "292", "293", "294", "295", "296", "297", "298", "299", "300", "301", "302", "303", "304", "305", "306", "307", "308", "309", "310", "311", "312", "313", "314", "316", "317", "318", "319", "320", "321", "322", "323", "324", "325", "326", "327", "328", "329", "330", "331", "332", "333", "334", "335", "336", "337", "338", "339", "340", "341", "342", "343", "344", "345", "346", "347", "348", "349", "350", "351", "352", "353", "354", "355", "356", "357", "358", "360", "361", "362", "363", "364", "365"), class = "factor"), Mesure = c(8, 8, 9.5, 10, 9.5, 10.7, 10.7, 8.5, 9.8, 9.8, 10.3, 10.5, 10.4, 10.5, 11.7, 10.6, 10.6, 13.6, 11.1, 11.1, 11.4, 11, 11, 13, 11.3, 11.3, 12.8, 13.8, 14.4, 14.5, 13.5, 13.9, 15.1, 13.8, 12.5, 12.6, 13.4, 12.6, 12.6, 15, 14.1, 14.3, 17.1, 14.7, 14.9, 18.6, 19, 20, 18.8, 19.2, 19.3, 18.9, 17.7, 15.9, 16.2, 14.2, 14.7, 14.9, 15.3, 15.3, 16, 18.4, 18.4, 20, 20.4, 17.8, 17.8, 19.2, 17.5, 17.7, 17.6, 17.7, 21.3, 22.2, 22.2, 22.6, 20.9, 19.2, 20.2, 21.1, 19.7, 19.7, 18, 17.6, 18.9, 18.7, 16.9, 17.8, 17.2, 18.1, 17.6, 18.9, 17, 16.9, 15, 14.1, 13, 12.6, 11.7, 11, 10.7, 10.3, 10.4, 9.5, 8.2, 8.9, 10.1, 10.8, 10.9, 12.8, 13.1, 12.1, 14.8, 14.2, 17, 17.6, 17.8, 14.1, 17.7, 14.7, 14.7, 14.2, 15.3, 17.8, 18, 19.8, 18.3, 19.4, 16.9, 19, 17.6, 17.4, 16.4, 16.4, 15.8, 15.1, 14.8, 14.1, 14.2, 12.8, 12, 10.3, 10.7, 10.2, 9.7, 9.4, 7.7, 8, 11, 11.4, 10.7, 12, 13.1, 12.7, 14.3, 15.6, 14.7, 15, 18.5, 17.2, 19.3, 12.8, 15, 15, 17.7, 14.9, 17.3, 15.6, 16.6, 18.5, 16.4, 17.3, 16.4, 16.2, 15.1, 12.7, 10, 8.3, 7.3, 7, 8, 7.4, 7.4, 8.4, 9.2, 9.4, 12.7, 11.5, 14.2, 12.7, 12.5, 15.7, 17.8, 18.9, 17.4, 16.6, 18.7, 20.7, 20, 18, 18.9, 15.7, 16.1, 18.1, 17.6, 14.7, 12.1, 11, 11.8, 11, 12.4, 14.5, 12.7, 12.6, 14.4, 17.9, 16.6, 14.5, 16.2, 17.1, 18.7, 17.9, 17.4, 17.2, 18, 16.4, 14.4, 15.5, 14.2, 13.8, 12.1, 11.3, 8.9, 9.8, 9.8, 8.9, 8.4, 8.9, 8.9, 10.6, 10.2, 10.2, 10.8, 11.7, 11.7, 14, 16.2, 16.2, 14, 15, 15.6, 12.9, 12.9, 15, 15.7, 15.7, 16.6, 17.4, 12.9, 16.9, 15.5, 13.9, 13.9, 16.1, 16.1, 14.6, 14.1, 18, 18.6, 12.4, 12.4, 15.4, 15.4, 15.8, 17.2, 16.5, 16.5, 16.7, 16.8, 15.9, 14.3, 15.4, 15, 13.3, 13.2, 12.7, 11.4, 9.4, 6.9, 8.2, 8.4, 8.2, 9.5, 11.1, 11, 12.8, 12, 12.3, 13, 16.6, 13.5, 16.7, 14.2, 19.3, 13.7, 16.1, 14.2, 14.1, 17.2, 15, 17.3, 19.5, 16.2, 18.1, 17.4, 15.4, 16.9, 14.7, 16.6, 17.2, 16.6, 15.4, 11.8, 11.8, 10.2, 10, 7.1, 8.3, 8.2, 8, 9.8, 10.2, 12.1, 11.7, 13.4, 11.2, 13.1, 10.6, 13.2, 12.9, 14.6, 18, 12.7, 15.1, 16.3, 11.9, 15.7, 14.6, 17, 15.2, 17.5, 15, 16.3, 15.5, 15.7, 13, 7.7, 7.9, 8.4, 9.2, 8.7, 10, 12.1, 13.6, 15.3, 14.89, 13.05, 13.8, 14.89, 14.9, 16.41, 16.1, 16.39, 11.7, 14.8, 15.56, 16.72, 17, 18.07, 17.4, 15, 16.79, 18.27, 16.39, 15.6, 14.75, 13.87, 12.2, 11, 11.8, 9.71, 9.52, 10.47, 11.44, 12.05, 11.49, 11.6, 12.83, 14.05, 17.14, 12.6, 14.8, 12.6, 15.16, 16.1, 15.32, 16.8, 18.01, 15.5, 16.65, 18.8, 20.36, 16.8, 17.52, 15.6, 17.35, 15.8, 15.62, 14.86, 13.2, 12.11, 11.65, 12)), .Names = c("Date", "Annee", "Mois", "Jourannee", "Mesure"), class = "data.frame", row.names = c("7413", "7440", "16263", "19364", "16266", "22684", "22705", "9711", "18115", "18133", "20630", "21431", "21054", "21437", "26379", "22192", "22243", "34022", "24087", "24124", "25291", "23623", "23663", "31760", "24950", "24959", "31098", "34997", "37850", "38311", "33673", "35459", "40853", "34839", "29922", "30310", "33231", "30314", "30326", "40496", "36427", "37419", "53855", "39326", "40145", "64409", "69950", "81748", "66481", "72995", "74404", "68002", "58822", "45098", "47124", "36883", "39239", "40140", "41558", "41600", "45858", "63000", "63005", "81502", "84446", "59280", "59288", "72676", "57414", "58961", "58115", "58991", "89667", "91764", "91768", "92261", "87505", "72951", "83212", "88778", "78851", "78893", "60137", "58123", "68201", "65525", "52759", "59289", "55419", "61881", "58154", "68003", "53356", "52695", "40657", "36449", "31885", "30332", "26459", "23669", "22574", "20511", "20903", "16118", "8086", "12079", "19751", "22853", "23163", "30939", "32157", "27887", "39661", "36753", "53067", "57893", "59172", "36321", "58700", "39167", "39170", "36734", "41402", "59170", "59903", "79538", "62765", "75136", "52653", "69435", "57897", "56565", "48945", "48951", "44503", "40840", "39670", "36315", "36742", "30945", "27506", "20514", "22577", "20126", "17341", "15719", "6445", "7337", "23464", "25247", "22580", "27509", "32163", "30559", "37312", "43405", "39176", "40414", "63157", "54854", "74032", "30952", "40404", "40417", "58699", "40005", "56083", "43409", "51235", "63154", "49001", "56088", "48939", "46903", "40834", "30548", "19184", "8756", "4488", "3263", "7334", "5070", "5079", "9252", "14404", "15713", "30545", "25632", "36722", "30554", "29683", "44042", "59178", "67753", "56643", "51255", "65461", "86321", "81509", "59912", "67781", "44028", "46318", "61761", "57905", "39173", "27890", "23455", "26624", "23461", "29204", "38270", "30556", "30171", "37778", "59417", "51253", "38275", "46909", "53720", "65458", "59418", "56588", "55061", "59906", "48962", "37783", "42312", "36729", "34791", "27881", "24836", "12045", "17979", "17984", "12054", "9250", "12064", "12072", "22002", "20109", "20110", "22851", "26337", "26343", "35822", "46898", "46901", "35832", "40398", "43545", "31363", "31366", "40409", "44036", "44039", "51229", "56644", "31360", "52652", "42381", "35285", "35288", "46301", "46304", "38784", "36367", "59915", "64162", "29209", "29214", "41856", "41859", "44511", "54826", "50116", "50123", "51750", "52291", "45044", "37307", "41911", "40401", "32853", "32456", "30551", "25244", "15716", "3183", "8084", "9255", "8088", "16121", "24000", "23451", "30942", "27499", "28718", "31659", "51239", "33546", "51749", "36763", "74022", "34331", "46314", "36739", "36327", "54836", "40426", "56091", "76239", "46918", "61765", "56576", "41862", "52655", "39178", "51245", "54846", "51252", "41865", "26627", "26633", "20111", "19192", "3458", "8753", "8082", "7331", "18038", "20116", "27951", "26348", "33149", "24365", "32151", "22014", "32459", "31371", "38781", "59900", "30563", "40837", "47885", "27080", "44045", "38786", "53065", "41042", "57129", "40420", "47846", "42315", "44048", "31656", "6442", "7052", "9258", "14410", "10555", "19188", "27884", "33979", "41399", "39928", "32069", "34796", "39931", "40008", "49774", "46321", "48767", "26353", "39665", "43246", "52091", "53071", "61427", "56562", "40428", "52180", "62728", "48774", "43399", "39575", "35204", "28221", "23458", "26637", "17853", "16513", "21209", "25556", "27842", "25597", "25991", "31297", "36208", "54390", "30174", "39673", "30177", "41010", "46309", "41781", "52294", "61206", "42318", "51654", "66398", "84164", "52298", "57710", "43416", "56444", "44500", "43880", "39901", "32468", "28144", "26261", "27515")) here is an extract of my program p<-list() #Creating the graphs year by year for(a in 1: 10){ #selecting the year An<-baie[baie$Annee==unique(baie$Annee)[a],] moyparam<-ddply(An, .(Date, Annee, Mois, Jourannee), function(x) data.frame(Mesure=mean(x$Mesure))) p[[a]]<-ggplot(data=moyparam, aes(x=moyparam$Date, y=moyparam$Mesure))+geom_point()+theme_bw() } grid.arrange(p) #or multiplot(plotlist=p, layout=matrix(c(1:10),nrow=2,ncol=5, byrow=TRUE)) I manage to plot each graphs separately, they are even stored in a list, but when i display the list or when i try to do the multiple plot, i get a message: Error in data.frame(x = c(15349, 15365, 15377, 15392, 15411, 15412, 15419, : arguments imply differing number of rows Where am I wrong? Maybe the answer is simple, but i think i could use a new point of view on the problem. Thank you for any help you can give me. As an update: thank you to Roland and noah for pointing my errors and helping me so quickly! but here's a precision: I did not mention it previously, but my code is a bit more complicated than what is written here. In reality, i add a partially colored background on a "risk period" only on years where toxicity of the shelfish is observed (so that i can compare parameters on toxic years (precisely: on risk period) and non toxic years (on the entire year). so my code is testing if the year is toxic, and if so, it add a color background on the risk period. I did not put it before because my error occurs even without this test, and i mention it now because it explains why i can't use facets grid (or can i? is there a way i can add partially colored background only on some facets?)
If you correct your misuse of $ in aes() the code works as expected, p[[a]] <- ggplot(data=moyparam, aes(x=Date, y=Mesure)) + geom_point()+theme_bw() And here's a more concise way to do the processing: baie2 = plyr::ddply(baie, .(Date, Annee, Mois, Jourannee), summarise, Mesure = mean(Mesure)) base_plot = ggplot(baie2, aes(x=Date, y=Mesure)) + geom_point()+theme_bw() lp = plyr::dlply(baie2, "Annee", `%+%`, e1 = base_plot) from which you can arrange all plots in a page: gridExtra::grid.arrange(grobs = lp) Now, for the broader question, you have two options: use facetting for the year, and a loop / **ply to open a new page for each site base_plot + facet_wrap(~Annee, scales="free") use gridExtra::marrangeGrob, like grid.arrange above but automatically splits the layout into multiple pages if necessary. It also works with ggsave.