TLDR; is there a Julia version of R’s which() function?
I’m rewriting some code from R to Julia. I’ve gotten comfortable with the DataFrames subset function but in addition to returning rows I occassionally need to access relative to a specific row that meets a given condition. My data records a series of simulated aircraft flights. They always start at a given position but vary in end point and duration. To find the beginning of each run I subset the data as follows:
@subset(df,:XPOSITION.== df.XPOSITION[1])
I’d like to be able to get the last row of each run as well. In R I would use the which() function which returns a vector of indices in the original dataframe that match the given condition. Then I know that the end positions abutt the start positions and I can shift the correct elements of the start position vector to get the end position vector.
This works but adding in a column of row indices when my data is 6.2+ million rows long seems like a really inefficient way of getting the indices I need.
Unfortunately the data does not have the indivdual flights labeled. That is what I’m going to use the start and end index lists to do.
To get the index of the last row of I flight I know that it is the index one prior to the start of the next flight so for example if startIndex = [1,10,17,25] then the end index for flight 1 would be 9 (the index prior to the start of flight 2) and so forth so in this case endIndex = [9,16,24,nrow(df)].