Having two dataframes:

1. `URLSMMG` with 374 observations
2. `pagesVisited` with 99120 observations

I use the following function to `sum` all values from `pagesVisited` that satisfy two conditions, placing the result in a new column in `URLSMMG`:

```
# Calculate pageviews from MMG
for (i in 1:nrow(URLSMMG)) {
        URLSMMG$pageviewsMMGClick[i] <- sum(pagesVisited[
        which(pagesVisited[,11] == URLSMMG$URLWithoutParameters[i] &
        grepl(paste0("ic=", URLSMMG$Code[i]), pagesVisited$evar3) == TRUE),3])
}

```

Measuring the function execution time, it says the function needs about 4 minutes to end. I am happy with the result, as the output is the expected, but I am not sure if I am doing the calculation using the fastest method. Does someone knows another way of doing that in less time?