Question: I have below data in a big query table

```
col1    col2
abc 3/22/2020
abc 3/4/2020
xyz 3/22/2020
xyz 3/4/2020

```

I am trying to get below output.

```
col1    col2
abc 3/22/2020
xyz 3/22/2020

```

For this I have tried using the rank() OVER Partition clause, but no luck. Please advise.

```
select * from (select col1, col2 RANK() over (partition by col1, col2 order by col1, col2 desc) as r1 from table1) temp
where temp.r1 = 1

```

Answer: 
We can use `lapply` to add offset 0's using `rep`

```
out <- lapply(seq_along(list_num), function(n) c(rep(0, n-1), list_num[[n]]))
out

#[[1]]
#[1] 1 1 1 1 1

#[[2]]
#[1] 0 2 2

#[[3]]
#[1] 0 0 5

#[[4]]
#[1] 0 0 0 3 3 3 3 3

```

We can then add `NA`'s to make length equal and calculate row-wise sum. 

```
rowSums(sapply(out, `[`, 1:max(lengths(out))), na.rm = TRUE)
#[1] 1 3 8 4 4 3 3 3

```
The requirement does not seem very hard to code in C++, hence here is an option using `Rcpp`:

```
library(Rcpp)
cppFunction("NumericVector psumUnevenList(List a, int len) {
    NumericVector res(len), v;

    for (int i=0; i<a.length(); i++) {
        v = a[i];
        for (int j=0; j<v.length(); j++) {
            res[i+j] += v[j];
        }
    }

    return res;
}")
maxn <- max(seq_along(list_num) - 1L + lengths(list_num))
psumUnevenList(list_num, maxn)
#[1] 1 3 8 4 4 3 3 3

```