Re: [Rd] changing the mode of a factor (PR#9675)

From: <ripley_at_stats.ox.ac.uk>
Date: Mon, 14 May 2007 13:37:02 +0200 (CEST)


  This message is in MIME format. The first part should be readable text,   while the remaining parts are likely unreadable without MIME-aware tools.

--27464147-942662499-1179141762=:28940

Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-1; FORMAT=flowed
Content-Transfer-Encoding: 8BIT
Content-ID: <Pine.LNX.4.64.0705141227241.28940_at_gannet.stats.ox.ac.uk>

How about the following NEWS item (a bug fix)

     o	Assigning class "factor" to an object now requires it has
 	integer (and not say double) codes.

? (Changing the mode to double amounted to creating a new double vector and then assigning the attributes of the old object including the class. We gave a more specific error message in this case in an attempt to be helpful ....)

>From ?factor

      'factor' returns an object of class '"factor"' which has a set of
      integer codes the length of 'x' with a '"levels"' attribute of
      mode 'character'.  If 'ordered' is true (or 'ordered' is used) the
      result has class 'c("ordered", "factor")'.

So a factor necessarily has integer codes. That you were able to change the mode in earlier versions of R was a bug that has been fixed.

You may well want one of the answers to FAQ 7.10.

Please take note of the 'BUGS' section in the FAQ and the posting guide: three incorrect bug items in one day is unhelpful.

On Fri, 11 May 2007, frederic.gosselin_at_cemagref.fr wrote:

> Full_Name: Frédéric Gosselin
> Version: 2.5 vs 2.4 and 2.2.1
> OS: windows XP
> Submission from: (NULL) (195.221.118.52)
>
>
> #############
> L3 <- LETTERS[1:3]
> (d <- data.frame(cbind(x=1, y=1:10), fac=as.factor(sample(L3, 10,
> repl=TRUE))))
> mode(d[,3])<-"numeric"
> ###############
>
> when trying to change the mode of a column in a data.frame that is a factor to
> numeric(cf. preceding code), the following error occurs (in French) in R 2.5:
>
> Erreur dans `storage.mode<-`(`*tmp*`, value = "double") :
> le mode de stockage d'un objet "factor" ne peut être modifié
>
> The same thing works fine in R2.4 and 2.2.1.
>
> It does not seem to correspond to new things announced in the NEWS file for the
> 2.5 version...
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595
--27464147-942662499-1179141762=:28940--

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Mon 14 May 2007 - 11:43:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 May 2007 - 13:33:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.