Re: [R] generating factors from the edit function

2011-03-05 Thread Dieter Menne
Erin Hodgess-2 wrote: Here is a little function that I put together: fact1 function(x) { n - ncol(x) for(i in 1:n) { if(mode(x[,i])==character)x[,i] - factor(x[,i]) } return(x) } See http://www.mail-archive.com/r-help@stat.math.ethz.ch/msg22459.html for a more R-ish approach.

[R] generating factors from the edit function

2011-03-04 Thread Erin Hodgess
Dear R People: If I use the fix or edit function for a new data frame, I would like to have my character data as factors. Is there a built in way to do this, please? Here is what I did: test2.df - data.frame() test2.df - fix(test2.df,factor.mode=character) str(test2.df) 'data.frame': 5

Re: [R] generating factors from the edit function

2011-03-04 Thread Ista Zahn
Hi Erin, I would set up the data.frame the way you want it before calling fix(). Something like test2df - data.frame(v1=numeric(), v2=factor()) test2df - fix(test2df) Best, Ista On Sat, Mar 5, 2011 at 4:34 AM, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: If I use the fix or

Re: [R] generating factors from the edit function

2011-03-04 Thread Erin Hodgess
Here is a little function that I put together: fact1 function(x) { n - ncol(x) for(i in 1:n) { if(mode(x[,i])==character)x[,i] - factor(x[,i]) } return(x) } It does the trick. I'm sure that there are better ways, but this seems ok. Thank you!!! Sincerely, Erin On Fri, Mar 4, 2011 at 10:42

Re: [R] generating factors from the edit function

2011-03-04 Thread Joshua Wiley
Hi Erin, I am assuming this is for pedagogical purposes (i.e., make R less intimidating by not reading data in). If that is true, you may just want to automate the whole process. I am typically twitchy about using assign(), but fix does it and again if only for introducing students to R.