Re: [R] Apply as.factor (or as.numeric etc) to multiple columns

2009-06-25 Thread SIES 73
: Tue, 23 Jun 2009 15:23:54 -0600 From: Mark Na mtb...@gmail.com Subject: [R] Apply as.factor (or as.numeric etc) to multiple columns To: r-help@r-project.org Message-ID: e40d78ce0906231423m4c3da14i2f6270f92463c...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 Hi R-helpers, I

Re: [R] Apply as.factor (or as.numeric etc) to multiple columns

2009-06-25 Thread Gabor Grothendieck
-- Message: 99 Date: Tue, 23 Jun 2009 15:23:54 -0600 From: Mark Na mtb...@gmail.com Subject: [R] Apply as.factor (or as.numeric etc) to multiple columns To: r-help@r-project.org Message-ID:        e40d78ce0906231423m4c3da14i2f6270f92463c...@mail.gmail.com Content

Re: [R] Apply as.factor (or as.numeric etc) to multiple columns

2009-06-25 Thread SIES 73
...@gmail.com Subject: Re: [R] Apply as.factor (or as.numeric etc) to multiple columns That's quite nice. Three comments: - colClasses() in R.utils is similar, except for the particular codes and classes supported, to expandClasses() here. - not sure if this is important but if as() were the last

[R] Apply as.factor (or as.numeric etc) to multiple columns

2009-06-23 Thread Mark Na
Hi R-helpers, I have a dataframe with 60columns and I would like to convert several columns to factor, others to numeric, and yet others to dates. Rather than having 60 lines like this: data$Var1-as.factor(data$Var1) I wonder if it's possible to write one line of code (per data type, e.g.

Re: [R] Apply as.factor (or as.numeric etc) to multiple columns

2009-06-23 Thread hadley wickham
Hi Mark, Have a look at colwise (and numcolwise and catcolwise) in the plyr package. Hadley On Tue, Jun 23, 2009 at 4:23 PM, Mark Namtb...@gmail.com wrote: Hi R-helpers, I have a dataframe with 60columns and I would like to convert several columns to factor, others to numeric, and yet

Re: [R] Apply as.factor (or as.numeric etc) to multiple columns

2009-06-23 Thread Gabor Grothendieck
Try this: ix - 2:5 DF[ix] - lapply(DF[ix], as.numeric) nms - c(x, y) DF[nms] - lapply(DF[nms], as.factor) On Tue, Jun 23, 2009 at 5:23 PM, Mark Namtb...@gmail.com wrote: Hi R-helpers, I have a dataframe with 60columns and I would like to convert several columns to factor, others to

Re: [R] Apply as.factor (or as.numeric etc) to multiple columns

2009-06-23 Thread baptiste auguie
Wacek helped me out on a similar topic a while back, ize = function (d, columns = names(d), izer = as.factor) { d[columns] = lapply(d[columns], izer) d } d = data.frame(x=1:10, y=1:10, z =1:10) str( ize(d, 'y') ) # y is now a factor str( ize(d, 1:2, `cumsum`) ) # x and y are affected