umair durrani
2014-Jan-25 01:09 UTC
[R] R 3.0.2 How to Split-Apply-Combine using various Columns
Hello everyone, I have a large vehicle trajectory data of which following is a small part: vehicle frame globalx class velocity lane 1 221 6451260 2 23.37 5 1 222 6451261 2 23.16 5 1 223 6451263 2 22.94 5 1 224 6451264 2 22.85 5 2 115 6451181 3 35 4 2 116 6451184 3 35.01 4 2 117 6451186 3 35.03 4 2 118 6451188 334.92 4 2 119 6451191 334.49 4 2 120 6451193 333.66 4 2 121 6451195 332.5 4 vehicle = unique ID of vehicle. It is repeated (in column) for every frame in which it was observedframe= ID of the frame in which the vehicle was observed. One frame is 0.1 seconds long.class = class of vehicle i.e. 1=motorcycle, 2=car, 3=truckvelocity= velocity of vehicle in feet per secondlane= lane number in which vehicle is present in a particular frame 'frame' number can also repeat e.g. in frame 120 the example data shows vehicle 2 was observed but in the original data many more vehicle might have been observed in this frame. Similarly, 'class' is defined above and all three classes are present in the original data (here example data only shows classes 2 and 3 i.e. cars and trucks). I need to determine two things:1) Number of vehicles observed in every 30 seconds i.e. 300 frames2) Average velocity of each vehicle class in every 30 seconds This means that the first step might be to determine the minimum and maximum frame numbers and then divide them in slots so that every slot has 300 frames. In my original data I found 22 as min and 9233 as max frame number. This makes 30 time slots as 22-322, 322-622, ..., 9022-9233. I need following output: Timeslot lane Totalcars Totaltrucks Totalmotorcycles AverageVelocity-cars AverageVelocity-trucks AverageVelocity-motorcycles 22-322 322-622 622-922 . . . 9022-9233 I have tried many things and also used some suggestions from stackoverflow but still am unable to get output like this with input data. Please help. Umair Durrani email: umairdurrani@outlook.com [[alternative HTML version deleted]]