Question: I've just started to get into the world of python and frankly, I'm a little bit confused about the results the following implementation gives me.

It's just a recursive function that should output all of the permutations of a given list. I know there's probably a thousand better ways of doing the same, but this is what I came up with. What strikes me is that the exact same code works just fine in C++; I believe it may have something to do with the way variables are passed in python\*, but I'm not sure. 

The code:

```
def permut (s, permut_s):
    if not s:
        return permut_s
    if not permut_s:
        last_s = s[-1]
        s.pop (-1)
        permut_s = [[last_s]]
        return permut (s, permut_s)
    new_permut_s = []
    last_s = s[-1]
    for x in range (len (permut_s)):
        aux = permut_s[x]
        aux = [last_s] + aux
        new_permut_s.append (aux)
        for y in range (len (aux) - 1):
            aux_elem = aux[y]
            aux[y] = aux[y + 1]
            aux[y + 1] = aux_elem
            new_permut_s.append (aux)
    s.pop (-1)
    return permut (s, new_permut_s)

def main(s, permut_s):
    print (permut (s, permut_s))

main ([1,2,3], [])

```

\*the reason I say this is because doing some prints in between lines shows that before the first non-trivial execution, new\_permut\_s = [[2,3]], and after, it is [[3,2],[3,2]], when it should be [[2,3],[3,2]]

Thanks a lot !

Answer: 
Assuming you just want to keep the first row of two duplicates:

```
df <- df[!duplicated(df[c('date')]),]

df

##     date   hrs
##6/14/2018 364.8
##6/15/2018 372.6
##6/21/2018 383.3
##6/22/2018 394.5
##6/25/2018 411.0
##6/28/2018 423.9

```
**1) zoo** You can create a zoo series without duplicates by using `read.zoo` and specifying an `aggregate` function like this. In the example we assumed you want the last of any duplicates but we can use `mean`, `median`, `function(x) head(x, 1)` or other functions for other aggregates.

```
library(zoo) 
z <- read.zoo(DF, format = "%m/%d/%Y", aggregate = function(x) tail(x, 1))

```

Now `plot(z)`, `lattice::xyplot(z)` or `ggplot2::autoplot(z)` will plot it, `fortify.zoo(z)` will convert it to a data frame, etc.

**2) base** We can use `aggregate` in base like this:

```
DF2 <- transform(DF, Date = as.Date(Date, "%m/%d/%Y"))
aggregate(Hrs ~ Date, DF2, function(x) tail(x, 1))

```

or we can use any of the aggregate functions mentioned in (1).

```
## Note

Lines <- " Date        Hrs
6/14/2018   364.8
6/15/2018   372.6
6/15/2018   381.9
6/21/2018   383.3
6/22/2018   394.5
6/25/2018   411
6/28/2018   423.9
6/28/2018   424.9"
DF <- read.table(text = Lines, header = TRUE)

```