Dear R-users

I need to convert a matrix with three columns in a new  array  with 
multiple columns.

For example,

oldmatrix

1 	4	5
1	54	52
1	9	43
2	32	5
2	54	6
2	76	6
3	54	54
3	543	7
3       54     6

newmatrix

5  	5	54
52	6	7
43	6	6


if the first column have a new value then add a column to the new 
matrix and the new[i,j] <- old[,3][i]

I write this code, but my initial matrix is very large and the 
convertion is very slow. How I can optimise that code?



  converter <- function(oldmatrix) {
   nr <- sapply(oldmatrix[,1], nrow)
  temporario <- oldmatrix[,1][1]
  j <- 1
  nn<-1
   for (i in seq(along=nr)) {
   if (temporario == oldmatrix[,1][i]) {
   nn <- nn +1
   }
   else
    {
   j <- j + 1
    }
   temporario <- oldmatrix[,1][i]
   }

nn<-i/j
newmatrix<-array(dim=c(nn, j))
  temporario <- oldmatrix[,1][1]
  j <- 1
  i<-1
   for (i in seq(along=nr)) {
   if (temporario == oldmatrix[,1][i]) {
   newmatrix[,j][i] <- oldmatrix[,3][i]
   }
   else
    {
   j <- j + 1
    }
   temporario <- oldmatrix[,1][i]
   }
return(newmatrix)
   }

Thanks a lot

Jorge
	[[alternative text/enriched version deleted]]


