I am trying to convert long data form into wide data form in R. 
For instance, I have following data frame:

```
a = rep(c("A","B","C","D"),4)
b = rep(c("COL1","COL2","COL3","COL4"),4)
val = 101:116
df = as.data.frame(cbind(a,b,val))
df

```

I would like to see the result as:

```
row <- as.list(levels(df$a))
col <- as.list(levels(df$b))

test <- data.frame()

i = 1

  for (j in 1:4) {
    for(k in 1:4){
      test[j,k]  =   df$val[i]
      i = i + 1 
    }
  }

colnames(test) <- c("COL1","COL2","COL3","COL4")
rownames(test) <- c("A","B","C","D")
test

```

Would appreciate if you could suggest an elegant solution using some handy function.
Thanks,
Qasim