[R] Factor levels
ggrothendieck at gmail.com
Tue Aug 28 22:16:39 CEST 2007
Its not clear from your description what you want.
Could you be a bit more specific including an example.
On 8/28/07, Sébastien <pomchip at free.fr> wrote:
> Thanks Gabor, I have two questions:
> 1- Is there any difference between your code and the following one, with
> regards to Fld2 ?
> ### test ###
Input <- "Fld1 Fld2
> read.table(textConnection(Input), header =
DF$Fld2<-factor(DF$Fld2,levels= c("C", "A", "B")))
> 2- do you see any way to bring flexibility to your method ? Because, it
> looks to me as, at this stage, I have to i) know the order of my levels
> before I read the table and ii) create one class per factor.
> My problem is that I am not really working on a specific dataset. My goal is
> to develop R scripts capable of handling datasets which have various
> contents but close structures. So, I really need to minimize the quantity of
> "user-specific" code.
> Gabor Grothendieck a écrit :
> You can create your own class and pass that to read table. In
> below Fld2 is read in with factor levels C, A, B
function(from) factor(from, levels = c("C", "A", "B")))
> test ###
Input <- "Fld1 Fld2
> read.table(textConnection(Input), header = TRUE,
colClasses = c("numeric",
DF <- read.table(textConnection(Input), header =
colClasses = list(Fld2 = "my.levels"))
> Sébastien <pomchip at free.fr> wrote:
> Dear R-users,
I have found this not-so-recent post in the archives
> while I was
looking for a particular way to reorder factor levels. The
addressed by the author was to know if the read.table function
> could be
modified to order the levels of newly created factors "according to
order that they appear in the data file". Exactly what I am looking
As there was no reply to this post, I wonder if any move have been
towards the implementation of this suggestion. A quick look
?read.table tells me that if this option was implemented, it was not
the read.table function...
PS: I am sorry to post so many
> messages on the list, but I am learning R
(basically by trials & errors ;-)
> ) and no one around me has even a
slight notion about
R-help at stat.math.ethz.ch
> read the posting guide
> commented, minimal, self-contained, reproducible code.
More information about the R-help