Anyone have any idea why this code is only iterating through once. The main problem I am getting is that in line 141, the filter to DeviceID == user, Time == day is doing absolutely nothing. When I check in the environment, these values of user and day seem right (see attached screenshots of environment), but the data frame final_locations_ID is not filtered to DeviceID == user, Time == day, but also isn't unfiltered (values are missing that don't really make sense). This is my first time using for loop in r, is using <- still appropriate or is this causing my issues. The next for loop, which aims to find each distinct cluster, and record the mean lat and lon points, but num only has the value of 1, which means only 1 cluster is being detected which doesn't make a ton of sense.
The goal of the code is to iterate through each user in users, then iterate through each day for each user. Run dbscan for that particular user on that day, then finding each distinctive cluster, append the mean lat and lon coordinates of each cluster for that user on that day to a list.
cluster_info <- c("hi", "hello")
for(user in users){
for(day in days_distinct){
final_locations_ID <- final_locations %>% filter(DeviceID == user, Time == day)
trajectory_cluster <- dbscan(select(final_locations_ID, lat, lon), eps = .01, minPts = 8)
final_locations_cluster <- final_locations_ID %>% mutate(Cluster = trajectory_cluster$cluster)
numbers <- distinct(final_locations_cluster, Cluster) %>% filter(Cluster != "0")
for(num in numbers){
final_cluster_num <- final_locations_cluster %>% filter(Cluster == num)
cluster_info <- c(cluster_info, paste("(", mean(final_cluster_num$lat), ",", mean(final_cluster_num$lon), ")"))
}
}
}
cluster_info