I have a data frame of vehicle trajectories. Here's a snapshot:
>dput(head(df))structure(list(vehicle = c(2L, 2L, 2L, 2L, 2L, 2L), frame = 43:48,     globalx = c(6451214.156, 6451216.824, 6451219.616, 6451222.548,     6451225.462, 6451228.376), class = c(2L, 2L, 2L, 2L, 2L,     2L), velocity = c(37.76, 37.9, 38.05, 38.18, 38.32, 38.44    ), lane = c(2L, 2L, 2L, 2L, 2L, 2L)), .Names = c("vehicle", "frame", "globalx", "class", "velocity", "lane"), row.names = c(NA, 6L), class = "data.frame")
where, vehicle= vehicle id, frame= frame id of time frames in which it was observed, globalx = x coordinate of the front center of the vehicle, class=type of vehicle (1=motorcycle, 2=car, 3=truck), velocity=speed of vehicles in feet per second, lane= lane number (there are 6 lanes).The 'frame' represents one tenth of a second i.e. one frame is 0.1 seconds long. At frame 't' the vehicle has globalx coordinate x(t) and at frame 't-1' (0.1 seconds before) it was x(t-1). If the reference location has globalx coordinate=6451179.1116 then I simply want a new column in df called 'u' which has 'yes' in the row where globalx of the vehicle was greater than reference coordinate at 'U' AND the previous consecutive globalx coordinate of this vehicle was less than reference coordinate at 'U'(i.e. reference coordinate is between the 2 locations of vehicle in two consecutive frames). This means that if df has 100 vehicles then there will be 100 'yes' in 'u' column because every vehicle will meet the above criteria only once. I have tried to do this by running the function with ifelse and also tried to do the same using a for loop but it doesn't work for me.


 		 	   		  
	[[alternative HTML version deleted]]

