Re: [R] How to change the class of data?

2008-06-12 Thread Gabor Grothendieck
Try this workaround: library(methods) setClass("of") setAs("character", "of", function(from) as.ordered(from)) Input <- "A B b 1 c 2 a 3 " DF <- read.table(textConnection(Input), header = TRUE, colClasses = c("of", "numeric")) str(DF) On Thu, Jun 12, 2008 at 4:57 AM, Birgitle <[EMAIL PROTECTE

Re: [R] How to change the class of data?

2008-06-12 Thread Prof Brian Ripley
On Thu, 12 Jun 2008, Birgitle wrote: I have an additional question concerning to this topic. I usually use something liek that: read.table(, colClasses=c("numeric", "factor", "character", "my.funny.class")) but why can I not implement "ordered.factor" in there? Because the help page s

Re: [R] How to change the class of data?

2008-06-12 Thread Birgitle
I have an additional question concerning to this topic. I usually use something liek that: read.table(, colClasses=c("numeric", "factor", "character", "my.funny.class")) but why can I not implement "ordered.factor" in there? Birgit Kenn Konstabel wrote: > > Conversion to factor may hap

Re: [R] How to change the class of data?

2008-06-12 Thread Kenn Konstabel
Conversion to factor may happen (and often does) when you read in data with read.table(). So one solution may be reading in the same data again in a slightly different way: read.table(file="mydatafile", as.is=TRUE) # see also ?read.table You can also specify a class to each column of the data you

Re: [R] How to change the class of data?

2008-06-12 Thread Philipp Pagel
On Thu, Jun 12, 2008 at 03:42:23AM -0400, Charilaos Skiadas wrote: > Seeing how there have been three wrong answers so far, I should point > out that: > > 1) This is an FAQ: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How- > do-I-convert-factors-to-numeric_003f Going over the r-help archive,

Re: [R] How to change the class of data?

2008-06-12 Thread Charilaos Skiadas
ass(c) in the case of a matrix of factor,try apply(matrix,1, as.numeric) Cheers A. - Messaggio originale - Da: Qman Fin <[EMAIL PROTECTED]> A: r-help@r-project.org Inviato: Giovedì 12 giugno 2008, 8:24:08 Oggetto: [R] How to change the class of data? Hi all, I have some data x, which are a

Re: [R] How to change the class of data?

2008-06-12 Thread anna freni sterrantino
nviato: Giovedì 12 giugno 2008, 8:24:08 Oggetto: [R] How to change the class of data? Hi all, I have some data x, which are actualy consisted of numerical enties. But the class of this matrix is set to be "factor" by someone else. I used "class(x)", it turns out to be "facto

Re: [R] How to change the class of data?

2008-06-12 Thread Christoph Heibl
Try: x <- factor(1:10) class(x) x + 1 class(x) <- "numeric" x+1 On Jun 12, 2008, at 8:24 AM, Qman Fin wrote: Hi all, I have some data x, which are actualy consisted of numerical enties. But the class of this matrix is set to be "factor" by someone else. I used "class(x)", it turns out to b

Re: [R] How to change the class of data?

2008-06-12 Thread Moshe Olshansky
om: Qman Fin <[EMAIL PROTECTED]> > Subject: [R] How to change the class of data? > To: r-help@r-project.org > Received: Thursday, 12 June, 2008, 4:24 PM > Hi all, > > I have some data x, which are actualy consisted of > numerical enties. But the > class of this matrix is se

Re: [R] How to change the class of data?

2008-06-12 Thread Charilaos Skiadas
On Jun 12, 2008, at 2:24 AM, Qman Fin wrote: Hi all, I have some data x, which are actualy consisted of numerical enties. But the class of this matrix is set to be "factor" by someone else. I used "class(x)", it turns out to be "factor". So I can not calculate them. The typical approach is

Re: [R] How to change the class of data?

2008-06-11 Thread Frankg
When you have a data X with a class factor, you can transform it to numeric as y<-as.numeric(X) to transform it to a factor again use y<-as.factor(X) -- View this message in context: http://www.nabble.com/How-to-change-the-class-of-data--tp17793351p17793713.html Sent from the R help mailing

[R] How to change the class of data?

2008-06-11 Thread Qman Fin
Hi all, I have some data x, which are actualy consisted of numerical enties. But the class of this matrix is set to be "factor" by someone else. I used "class(x)", it turns out to be "factor". So I can not calculate them. How can I turn them into numerical data so that I can apply math operations