I have a data frame that stores the amount someone spends per transaction for this month. I'm trying to create a loop that checks for repeated user IDs, then sums and stores the amount they spent in total in the first record that they appear. It should set the amount they spent in any other occurrences to 0.
I keep getting "Error: No loop for break/next, jumping to top level" when I stop it from running:
# Number of trips
numTrips <- NROW(tripData)
# For each trip in data
for (i in 1:numTrips){
# For each trip after i
for (j in ((i+1): numTrips)){
# If the user ID's match, sum prices
if (tripData[i,]$user_id == tripData[j,]$user_id){
tripData[i,]$original_price <- tripData[i,]$original_price + tripData[j,]$original_price
tripData[j,]$original_price <- 0
}
}
}
Can someone please help?