Hi Lorenzo, maybe the following example is of use? a <- matrix(1:25,5,5) stack(as.data.frame(a[, c(1,3,5,2,4)])) Note that 'stack' takes a data frame or list as first argument (not a matrix). Therefore the matrix is first converted to a data frame using 'as.data.frame'. Christian