[R] as.integer

Erik Iverson eriki at ccbr.umn.edu
Mon Jun 7 22:48:35 CEST 2010


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



More information about the R-help mailing list