I have a large data frame data
with a number of vehicles and their geo spatial location.I was able to run a loop to subset the data for each vehicle id using the following code.
uniq <- unique(unlist(data$vehicleid))
for (i in 1:length(uniq)){
data_1 <- subset(data, vehicleid == uniq[i])
#your desired function
}
I need to write a function so that I can extract the first row of each subset and get all the extracted rows in a new separate data frame. How do I do that?
Consider the often overlooked
by
which can subset dataframes by one or more factors and run subset dataframes through a function:Here's an example of extracting first row of 4 ids
Alternative: