Now that I'm getting back into R, the things it can do reminds me of other things I used to do when I used SAS as a supply chain intern. For example, grouping data by a timestamp and taking the first/last element from the timestamp by using a keyword like "last" or "first". Fun stuff!
I'm looking at particle cloud weights today. I've plotted the cloud weights for each timestamp in Excel by creating a scatter plot with an X axis of each timestamp and a Y axis of the individual particles' weight at that timestamp. The "normal" plots and the "kidnapped" plots are easily differentiated:
Kidnapped:
Not Kidnapped:
Next, I looked at using R to group the particles by timestep and analyze the timesteps. Here's a script for getting the mean of each timesteps' particle weights:
1. Import the CSV:
mytable<-read.csv(<CSVpath>,header=TRUE,sep="\t")
2. Convert to a data frame:
values<-data.frame(mytable)
The piece de resistance: using the aggregate() function and specifying Time as the column by which I want the data to be grouped
3. xyz<-aggregate(x=values, by=list(unique.values=values$Time), FUN=mean)
Voila! Though, I don't know what the 4th column from the left is about.
Normal:
unique.values Time ParticleNumber ParticleWeight
1 18.87 18.87 999.5 0.000500000
2 26.15 26.15 250.0 0.001996008
3 26.39 26.39 250.0 0.001996008
4 26.62 26.62 250.0 0.001996008
5 27.14 27.14 250.0 0.001996008
6 30.28 30.28 250.0 0.001996008
7 31.71 31.71 250.0 0.001996008
8 33.60 33.60 250.0 0.001996008
9 34.48 34.48 250.0 0.001996008
10 35.82 35.82 250.0 0.001996008
11 36.20 36.20 250.0 0.001996008
12 36.42 36.42 250.0 0.001996008
13 37.60 37.60 250.0 0.001996008
14 39.22 39.22 250.0 0.001996008
15 40.80 40.80 250.0 0.001996008
16 42.29 42.29 250.0 0.001996008
17 43.54 43.54 250.0 0.001996008
18 44.79 44.79 250.0 0.001996008
19 45.16 45.16 250.0 0.001996008
20 46.39 46.39 250.0 0.001996008
21 48.29 48.29 250.0 0.001996008
22 49.11 49.11 250.0 0.001996008
23 49.39 49.39 250.0 0.001996008
24 50.24 50.24 250.0 0.001996008
25 50.77 50.77 250.0 0.001996008
26 51.29 51.29 250.0 0.001996008
27 52.99 52.99 250.0 0.001996008
28 54.71 54.71 250.0 0.001996008
29 58.20 58.20 250.0 0.001996008
30 60.42 60.42 250.0 0.001996008
31 61.28 61.28 250.0 0.001996008
32 61.85 61.85 250.0 0.001996008
33 63.77 63.77 250.0 0.001996008
34 65.99 65.99 250.0 0.001996008
35 66.43 66.43 250.0 0.001996008
36 67.50 67.50 250.0 0.001996008
37 68.43 68.43 250.0 0.001996008
38 68.50 68.50 250.0 0.001996008
39 68.72 68.72 250.0 0.001996008
40 68.90 68.90 250.0 0.001996008
41 69.35 69.35 250.0 0.001996008
42 70.96 70.96 250.0 0.001996008
43 71.17 71.17 250.0 0.001996008
44 71.36 71.36 250.0 0.001996008
45 71.69 71.69 250.0 0.001996008
46 75.19 75.19 250.0 0.001996008
47 75.94 75.94 250.0 0.001996008
48 77.48 77.48 250.0 0.001996008
49 79.60 79.60 250.0 0.001996008
50 80.53 80.53 250.0 0.001996008
51 80.81 80.81 250.0 0.001996008
52 81.26 81.26 250.0 0.001996008
53 81.31 81.31 250.0 0.001996008
54 83.78 83.78 250.0 0.001996008
55 85.54 85.54 250.0 0.001996008
56 85.72 85.72 250.0 0.001996008
57 86.10 86.10 250.0 0.001996008
58 86.72 86.72 250.0 0.001996008
59 88.28 88.28 250.0 0.001996008
60 88.75 88.75 250.0 0.001996008
61 88.84 88.84 250.0 0.001996008
62 89.12 89.12 250.0 0.001996008
63 89.34 89.34 250.0 0.001996008
64 89.76 89.76 250.0 0.001996008
65 90.40 90.40 250.0 0.001996008
66 90.44 90.44 250.0 0.001996008
67 90.71 90.71 250.0 0.001996008
68 91.15 91.15 250.0 0.001996008
69 91.40 91.40 250.0 0.001996008
70 92.65 92.65 250.0 0.001996008
71 92.84 92.84 250.0 0.001996008
72 94.27 94.27 250.0 0.001996008
73 95.67 95.67 250.0 0.001996008
74 96.96 96.96 250.0 0.001996008
75 98.51 98.51 250.0 0.001996008
76 101.10 101.10 250.0 0.001996008
77 101.90 101.90 250.0 0.001996008
78 101.99 101.99 250.0 0.001996008
79 102.57 102.57 250.0 0.001996008
80 103.00 103.00 250.0 0.001996008
81 104.61 104.61 250.0 0.001996008
82 105.99 105.99 250.0 0.001996008
83 106.55 106.55 250.0 0.001996008
84 106.72 106.72 250.0 0.001996008
85 107.74 107.74 250.0 0.001996008
86 108.20 108.20 250.0 0.001996008
87 108.40 108.40 250.0 0.001996008
88 108.85 108.85 250.0 0.001996008
89 109.31 109.31 250.0 0.001996008
90 111.11 111.11 250.0 0.001996008
91 112.32 112.32 250.0 0.001996008
92 112.50 112.50 250.0 0.001996008
93 114.44 114.44 250.0 0.001996008
94 116.50 116.50 250.0 0.001996008
95 117.14 117.14 250.0 0.001996008
96 117.29 117.29 250.0 0.001996008
97 117.64 117.64 250.0 0.001996008
98 118.40 118.40 250.0 0.001996008
99 118.66 118.66 250.0 0.001996008
100 118.70 118.70 250.0 0.001996008
101 120.13 120.13 250.0 0.001996008
102 120.86 120.86 250.0 0.001996008
103 121.40 121.40 250.0 0.001996008
104 122.85 122.85 250.0 0.001996008
105 124.50 124.50 250.0 0.001996008
106 124.86 124.86 250.0 0.001996008
107 125.22 125.22 250.0 0.001996008
108 126.61 126.61 250.0 0.001996008
109 128.70 128.70 250.0 0.001996008
110 128.76 128.76 250.0 0.001996008
111 128.87 128.87 250.0 0.001996008
112 129.17 129.17 250.0 0.001996008
113 129.42 129.42 250.0 0.001996008
114 129.63 129.63 250.0 0.001996008
115 130.26 130.26 250.0 0.001996008
116 130.46 130.46 250.0 0.001996008
117 130.60 130.60 250.0 0.001996008
118 130.88 130.88 250.0 0.001996008
119 132.27 132.27 250.0 0.001996008
120 132.44 132.44 250.0 0.001996008
121 132.62 132.62 250.0 0.001996008
122 132.98 132.98 250.0 0.001996008
123 133.35 133.35 250.0 0.001996008
124 133.50 133.50 250.0 0.001996008
125 134.17 134.17 250.0 0.001996008
126 134.74 134.74 250.0 0.001996008
127 135.36 135.36 250.0 0.001996008
128 135.60 135.60 250.0 0.001996008
Unfortunately, the mean of the cloud weights from the major kidnapping incident looks identical:
unique.values Time ParticleNumber ParticleWeight
1 19.57 19.57 999.5 0.000500000
2 28.58 28.58 250.0 0.001996008
3 28.76 28.76 250.0 0.001996008
4 28.95 28.95 250.0 0.001996008
5 29.24 29.24 250.0 0.001996008
6 31.79 31.79 250.0 0.001996008
7 33.14 33.14 250.0 0.001996008
8 34.52 34.52 250.0 0.001996008
9 35.79 35.79 250.0 0.001996008
10 37.20 37.20 250.0 0.001996008
11 38.53 38.53 250.0 0.001996008
12 39.42 39.42 250.0 0.001996008
13 39.53 39.53 250.0 0.001996008
14 39.96 39.96 250.0 0.001996008
15 40.28 40.28 250.0 0.001996008
16 43.80 43.80 250.0 0.001996008
17 44.95 44.95 250.0 0.001996008
18 46.43 46.43 250.0 0.001996008
19 47.78 47.78 250.0 0.001996008
20 48.81 48.81 250.0 0.001996008
21 49.18 49.18 250.0 0.001996008
22 51.19 51.19 250.0 0.001996008
23 53.23 53.23 250.0 0.001996008
24 53.82 53.82 250.0 0.001996008
25 53.90 53.90 250.0 0.001996008
26 55.38 55.38 250.0 0.001996008
27 56.65 56.65 250.0 0.001996008
28 58.33 58.33 250.0 0.001996008
29 59.97 59.97 250.0 0.001996008
30 62.59 62.59 250.0 0.001996008
31 64.49 64.49 250.0 0.001996008
32 65.53 65.53 250.0 0.001996008
33 66.70 66.70 250.0 0.001996008
34 67.93 67.93 250.0 0.001996008
35 69.70 69.70 250.0 0.001996008
36 69.85 69.85 250.0 0.001996008
37 70.14 70.14 250.0 0.001996008
38 70.55 70.55 250.0 0.001996008
39 71.66 71.66 250.0 0.001996008
40 71.94 71.94 250.0 0.001996008
41 72.27 72.27 250.0 0.001996008
42 72.56 72.56 250.0 0.001996008
43 72.96 72.96 250.0 0.001996008
44 74.51 74.51 250.0 0.001996008
45 74.93 74.93 250.0 0.001996008
46 75.36 75.36 250.0 0.001996008
47 75.50 75.50 250.0 0.001996008
48 75.71 75.71 250.0 0.001996008
49 78.99 78.99 250.0 0.001996008
50 80.40 80.40 250.0 0.001996008
51 81.76 81.76 250.0 0.001996008
52 83.46 83.46 250.0 0.001996008
53 84.67 84.67 250.0 0.001996008
54 84.99 84.99 250.0 0.001996008
55 85.32 85.32 250.0 0.001996008
56 85.86 85.86 250.0 0.001996008
57 87.74 87.74 250.0 0.001996008
58 89.19 89.19 250.0 0.001996008
59 89.39 89.39 250.0 0.001996008
60 89.61 89.61 250.0 0.001996008
61 90.11 90.11 250.0 0.001996008
62 90.88 90.88 250.0 0.001996008
63 92.79 92.79 250.0 0.001996008
64 93.37 93.37 250.0 0.001996008
65 93.85 93.85 250.0 0.001996008
66 94.31 94.31 250.0 0.001996008
67 94.67 94.67 250.0 0.001996008
68 94.86 94.86 250.0 0.001996008
69 95.21 95.21 250.0 0.001996008
70 95.77 95.77 250.0 0.001996008
71 96.94 96.94 250.0 0.001996008
72 97.24 97.24 250.0 0.001996008
73 98.72 98.72 250.0 0.001996008
74 100.32 100.32 250.0 0.001996008
75 102.60 102.60 250.0 0.001996008
76 102.72 102.72 250.0 0.001996008
77 105.42 105.42 250.0 0.001996008
78 105.60 105.60 250.0 0.001996008
79 105.79 105.79 250.0 0.001996008
80 106.21 106.21 250.0 0.001996008
81 106.55 106.55 250.0 0.001996008
82 106.87 106.87 250.0 0.001996008
83 108.58 108.58 250.0 0.001996008
84 110.10 110.10 250.0 0.001996008
85 110.11 110.11 250.0 0.001996008
86 110.47 110.47 250.0 0.001996008
87 111.41 111.41 250.0 0.001996008
88 111.76 111.76 250.0 0.001996008
89 112.12 112.12 250.0 0.001996008
90 112.29 112.29 250.0 0.001996008
91 113.31 113.31 250.0 0.001996008
92 113.90 113.90 250.0 0.001996008
93 115.19 115.19 250.0 0.001996008
94 115.64 115.64 250.0 0.001996008
95 115.99 115.99 250.0 0.001996008
96 118.30 118.30 250.0 0.001996008
97 119.62 119.62 250.0 0.001996008
98 120.46 120.46 250.0 0.001996008
99 120.66 120.66 250.0 0.001996008
100 120.99 120.99 250.0 0.001996008
101 121.24 121.24 250.0 0.001996008
102 121.64 121.64 250.0 0.001996008
103 122.23 122.23 250.0 0.001996008
104 122.50 122.50 250.0 0.001996008
105 123.95 123.95 250.0 0.001996008
106 124.70 124.70 250.0 0.001996008
107 125.12 125.12 250.0 0.001996008
108 125.20 125.20 250.0 0.001996008
109 125.92 125.92 250.0 0.001996008
110 127.14 127.14 250.0 0.001996008
111 128.39 128.39 250.0 0.001996008
112 129.26 129.26 250.0 0.001996008
113 129.72 129.72 250.0 0.001996008
114 131.23 131.23 250.0 0.001996008
115 132.64 132.64 250.0 0.001996008
116 133.30 133.30 250.0 0.001996008
117 133.49 133.49 250.0 0.001996008
118 133.90 133.90 250.0 0.001996008
119 134.53 134.53 250.0 0.001996008
120 134.67 134.67 250.0 0.001996008
121 134.80 134.80 250.0 0.001996008
122 135.00 135.00 250.0 0.001996008
123 136.33 136.33 250.0 0.001996008
124 136.46 136.46 250.0 0.001996008
125 136.80 136.80 250.0 0.001996008
126 137.10 137.10 250.0 0.001996008
127 137.29 137.29 250.0 0.001996008
128 137.62 137.62 250.0 0.001996008
129 137.82 137.82 250.0 0.001996008
130 139.17 139.17 250.0 0.001996008
131 139.46 139.46 250.0 0.001996008
132 139.72 139.72 250.0 0.001996008