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

```
Base R solution (two-steps): 

```
# Store a scalar valued at the length of longest vector in the list: 
vec_list_max_length <- max(lengths(vec_list))

# Set the length of each vector to be equal to the maximum length, rowbind the list
# together and get the sum of each row: 
rowSums(sapply(vec_list, function(x) {
  length(x) = vec_list_max_length
  return(replace(x, is.na(x), 0))
}))

```

Data:

```
vec_list <- list(c(1,1,1,1,1), c(0,2,2), c(0,0,5), c(0,0,0,3,3,3,3,3))

```