Greg.Snow at imail.org
Mon Jun 7 22:58:30 CEST 2010
Usually when read.table converts numbers to factors it means that there is a problem in the data file, an extra character somewhere. It is best to fix the problem in the source data (or a copy of the source data) so that the data imports properly rather than try to fix it post hoc. If that is not an option, then you can specify the colClasses argument to read.table to make sure that it reads the data into the type of variable that you want. If you really need the post read.table solution, then lapply will run the same function (as.integer) on each column of a data frame (element of a list).
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
greg.snow at imail.org
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of aledanda
> Sent: Monday, June 07, 2010 8:05 AM
> To: r-help at r-project.org
> Subject: [R] as.integer
> Is there a way to recursively change the variables imported with
> read.table(..) - and then attached with attach(..) - from as.factor to
> 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
> View this message in context: http://r.789695.n4.nabble.com/as-integer-
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help