Skip to content
Prev 87172 / 398506 Next

converting character matrix to a dataframe

On Fri, 24 Feb 2006, Prof Brian Ripley wrote:

            
[SNIP]
So I take it that this last solution would be:

(ch.mat <- matrix(c('a','s','*','f','w','*','k','*','*','f','i','o'), 
ncol=3))

(d4 <- data.frame(apply(ch.mat, 2, function(x) as.data.frame(I(x)))))
mode(d4[,1])
is.factor(d4[,1])

You're right that I'm not really concerned with computational efficiency, 
but only minimizing the amount of code that I have to write and remember. 
The solution seems to be that I should write a function that accomplishes 
this task, which I have done.  Thank you.

John