Sammy Zee
2011-Nov-11 05:41 UTC
[R] rbind.data.frame drops attributes for factor variables
Hi all, When I use rbind() or rbind.data.frame() to add a row to an existing dataframe, it appears that attributes for the column of type "factor" are dropped. I see the following post with same problem. However i did not see any reply to the following posting offering a solution. Could someone please help. http://r.789695.n4.nabble.com/rbind-data-frame-drops-attributes-for-factor-variables-td919575.html Thanks, Sanjay [[alternative HTML version deleted]]
Jeff Newmiller
2011-Nov-11 17:44 UTC
[R] rbind.data.frame drops attributes for factor variables
As the doctor says, if it hurts "don't do that". A factor is a sequence of integers with a corresponding list of character strings. Factors in two separate vectors can and usually do map the same integer to different strings, and R cannot tell how you want that resolved. Convert these columns to character before combining them, and only convert to factor when you have all of your possibilities present (or you specify them in the creation of the factor vector). --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Sammy Zee <szee2007 at gmail.com> wrote:>Hi all, > >When I use rbind() or rbind.data.frame() to add a row to an existing >dataframe, it appears that attributes for the column of type "factor" >are >dropped. I see the following post with same problem. However i did not >see >any reply to the following posting offering a solution. Could someone >please help. > >http://r.789695.n4.nabble.com/rbind-data-frame-drops-attributes-for-factor-variables-td919575.html > >Thanks, >Sanjay > > [[alternative HTML version deleted]] > >______________________________________________ >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.
Reasonably Related Threads
- With an example - Re: rbind.data.frame drops attributes for factor variables
- Is there way to add a new row to a data frame in a specific location
- rbind.data.frame drops attributes for factor variables
- pulling tree : semantics problem
- Setup problems, /dev/net/tun FD in bad state