This is my example:

```
df<-data.frame(ID=as.factor(c(rep("A",20),rep("B",15))),var=as.factor(c(rep("w",5),rep("x",10),rep("y",12),rep("z",8))), obs=runif(35,0,10))

```

What I want to do is, for each 'ID', to be able to select a single 'var', at random and possibly by selecting the 'var' with the most 'obs'. So for example, at random it could give this:

```
   ID  var       obs
6   A   x 3.44405412
7   A   x 1.50957637
8   A   x 8.22009420
9   A   x 7.47094473
10  A   x 8.26098410
11  A   x 9.62919537
12  A   x 0.10393890
13  A   x 0.11298502
14  A   x 4.33822574
15  A   x 4.20109035
28  B   z 1.07697286
29  B   z 8.40864310
30  B   z 7.62563257
31  B   z 0.06885177
32  B   z 4.33959316
33  B   z 7.98303782
34  B   z 8.38335593
35  B   z 4.52110318

```

Thank you in advance for your help.