Re: [R] as.integer

From: Erik Iverson <eriki_at_ccbr.umn.edu>
Date: Mon, 07 Jun 2010 15:48:35 -0500

  1. Give us a reproducible example.
  2. You probably don't want to use attach.
  3. Yes there is a way, but without an example, it's hard to say what will work. Assume a data.frame called df, maybe something like the following, which is untested...

df[is.factor(df)] <- lapply(df[is.factor(df)], function(x) as.numeric(as.character(x)))

aledanda wrote:
> Hi,
>
> Is there a way to recursively change the variables imported with
> read.table(..) - and then attached with attach(..) - from as.factor to
> as.integer?
> I have about 9 variables that are now recognized as factors but I need to do
> statistics on them so I need to change them in as.integer. It works, but I
> wonder if there is a way to to this for all the variables in one go.
>
> Thanks a lot for your help
>
> Ale



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 07 Jun 2010 - 21:08:54 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 Tue 08 Jun 2010 - 09:30:28 GMT.

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

list of date sections of archive