Re: [R] converting character matrix to a dataframe

2006-02-24 Thread John M. Miyamoto
On Fri, 24 Feb 2006, Prof Brian Ripley wrote: It is a bit more efficient to use as.data.frame in your apply. You could make a copy of as.data.frame.matrix (under another name) and remove the special-casing of character matrices. This would efficiently give you a data frame with character

[R] converting character matrix to a dataframe

2006-02-23 Thread John M. Miyamoto
Dear R-Help, Suppose I have a character matrix, e.g., (ch.mat - matrix(c('a','s','*','f','w','*','k','*','*','f','i','o'), ncol=3)) When I convert 'ch.mat' to a dataframe, the columns are converted to factors: (d1 - data.frame(ch.mat)) mode(d1[,1]) is.factor(d1[,1]) To prevent this, I

Re: [R] converting character matrix to a dataframe

2006-02-23 Thread Gabor Grothendieck
You could do it directly like this: structure(split(ch.mat, col(ch.mat)), row.names = 1:nrow(ch.mat), .Names = 1:ncol(ch.mat), class = data.frame) On 2/23/06, John M. Miyamoto [EMAIL PROTECTED] wrote: Dear R-Help, Suppose I have a character matrix, e.g., (ch.mat -

Re: [R] converting character matrix to a dataframe

2006-02-23 Thread Prof Brian Ripley
It is a bit more efficient to use as.data.frame in your apply. You could make a copy of as.data.frame.matrix (under another name) and remove the special-casing of character matrices. This would efficiently give you a data frame with character columns, but they would then not be treated 'AsIs'