Skip to content
Prev 308436 / 398506 Next

Matrix to data.frame with factors

Well, strictly speaking, this is still doing it "one variable at a
time." The interpreted loop is hidden, but it's still happening.

A loop free but clumsier approach is:

y <- data.frame(matrix(as.character(x),nrow = nrow(x)))

## Note also that the original column names will be lost and will have
to be added to the data frame.

It would also not surprise me if for such a small matrix that Rui's
version were faster.

-- Bert
On Fri, Oct 19, 2012 at 7:07 AM, Rui Barradas <ruipbarradas at sapo.pt> wrote: