<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 5.50.4611.1300" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=584294916-28062001>
<DIV><FONT face="Courier New" size=2><SPAN class=584294916-28062001>Antonio
Olinto wrote:</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" size=2><SPAN
class=584294916-28062001></SPAN></FONT> </DIV>
<DIV><FONT size=2><FONT face="Courier New"><SPAN
class=584294916-28062001>></SPAN>Dear R list members,</FONT></FONT></DIV>
<DIV><FONT size=2><FONT face="Courier New"><SPAN
class=584294916-28062001>></SPAN>I have a factor vector with levels 1, 2, 3
and 4. I want to re-group it: 1 and 2 will be 1 and 3 and 4 will be 2,
e.g.:</FONT></FONT></DIV>
<DIV><FONT size=2><FONT face="Courier New"><SPAN
class=584294916-28062001>></SPAN>x <- c(1, 1, 1, 2, 3, 2, 3, 4, ...
)</FONT></FONT></DIV>
<DIV><FONT size=2><FONT face="Courier New"><SPAN
class=584294916-28062001>></SPAN>x <- factor(x)</FONT></FONT></DIV>
<DIV><FONT size=2><FONT face="Courier New"><SPAN
class=584294916-28062001>></SPAN>What I have to do create a new vector where
1 1 1 2 3 2 3 4 ... is transformed in 1 1 1 1 2 1 2 2 ... ? (I have more than
200 lines in my dataframe)</FONT></FONT></DIV>
<DIV><FONT size=2><FONT face="Courier New"><SPAN
class=584294916-28062001>></SPAN>Thanks in advance.</FONT></FONT></DIV>
<DIV><FONT face="Courier New" size=2></FONT> </DIV><FONT face="Courier New"
size=2>I don't know if it is the best way to do it, but it
works:</FONT></SPAN></DIV>
<DIV><FONT face="Courier New" size=2><SPAN
class=584294916-28062001></SPAN></FONT> </DIV>
<DIV><FONT face="Courier New" size=2><SPAN class=584294916-28062001>x <-
as.numeric(x)</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" size=2><SPAN class=584294916-28062001>x[x<=2]
<- 1</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" size=2><SPAN class=584294916-28062001>x[x>2]
<- 2</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" size=2><SPAN class=584294916-28062001>x <-
as.factor(x)</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" size=2><SPAN
class=584294916-28062001></SPAN></FONT> </DIV>
<DIV><FONT face="Courier New" size=2><SPAN class=584294916-28062001>Best
regards,</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" size=2><SPAN
class=584294916-28062001></SPAN></FONT> </DIV>
<DIV><FONT face="Courier New" size=2><SPAN class=584294916-28062001>Philippe
Grosjean</SPAN></FONT></DIV>
<DIV><FONT face="Courier New" size=2><SPAN
class=584294916-28062001></SPAN></FONT> </DIV>
<DIV><FONT size=2><SPAN class=584294916-28062001><BR>
<P><FONT size=2><FONT
face="Courier New">...........]<(({°<...............<°}))><...............................<BR> )
) ) ) )
__
__<BR>( ( ( ( (
|__)
| _<BR> ) ) ) )
) |
hilippe
|__)rosjean<BR>( ( ( ( ( Marine Biol. Lab., ULB,
Belgium<BR> ) ) ) ) )
__<BR>( ( ( ( (
|\
/|
|__)<BR> ) ) ) )
) | \/ |ariculture
& |__)iostatistic<BR>( ( ( ( (<BR> ) ) )
) ) e-mail: phgrosje@ulb.ac.be<BR>( ( ( ( (
SciViews project coordinator (</FONT><A
target=_blank href="http://www.sciviews.org/"><FONT face="Courier New"
color=#000000>http://www.sciviews.org</FONT></A><FONT
face="Courier New">)<BR> ) ) ) )
)<BR>.......................................................................</FONT></FONT></P></SPAN></FONT></DIV></BODY></HTML>