I have two files :

1. Category:

```
Category_File = data.frame(c("A","A","A","A","A","B","B","B","C","C","D","D")) 
colnames(Category_File)= c("Category")

```

2. Agent:

```
Agent_File = data.frame(c("A","A","B","B","C"),c("X","Y","X","Z","Y"),c(2,2,2,1,2))
colnames(Agent_File) = c("Category","Agent","Tickets")

```

I need to allocate agents according to their category count.

Desired Output:

```
outputfile = data.frame(c("A","A","A","A","A","B","B","B","C","C","D","D"),c("X","X","Y","Y","NA","X","X","Z","Z","Y","NA","NA"))
colnames(outputfile) = c("Category","Agent")

```

Thanks