Skip to content

What is the correct way of using function C() for factors:

5 messages · Svetlana Eden, Corey Moffet, Spencer Graves +1 more

#
The funciton c() works differently for strings and for factors:


For strings:
[1] "a" "b"


For factors:
[1] 1 1


What should be the right technique for merging factors?
#
try:

l <- factor(c('a','b'))
l
At 12:15 PM 2/5/2004 -0600, Svetlana Eden wrote:
With best wishes and kind regards I am

Sincerely,

Corey A. Moffet
Rangeland Scientist

USDA-ARS
Northwest Watershed Research Center
800 Park Blvd, Plaza IV, Suite 105
Boise, ID 83712-7716

Voice: (208) 422-0718
FAX:   (208) 334-1502
#
To combine objects that are already factors, the solution I've 
found is to first coerce them to mode character: 

 > F1 <- factor("a")
 > F2 <- factor("b")
 > factor(c(as.character(F1), as.character(F2)))
[1] a b
Levels: a b

      hope this helps. 
      spencer graves
Corey Moffet wrote:

            
#
Did you mean the function c() or the function(C)?  They are not the same 
thing!

Also,  R does not have `strings' but it does have character vectors.
On Thu, 5 Feb 2004, Corey Moffet wrote:

            

  
    
#
I have two factors l1, l2, and I'd like to merge them.
Function c() does not give me the result I want:
[1] 1 2 1 2
I'd like to merge l1 and l2 and to get lMerge 
----------------------------------------------

[1] a b c d
Levels: a b c d

instead of 
----------

[1] 1 2 1 2
How should I do that?
---------------------