Or if you want to use recode (which you forgot to mention is in package car):
set.seed(1) df1<- c(sample(1:12, 50, replace=TRUE)) # sample data library(car) recode(df1, "c(1, 2, 3, 4, 11, 12)='invierno'; 5:10='verano'") ---------------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of arun > Sent: Saturday, August 11, 2012 5:17 PM > To: Dominic Roye > Cc: R help > Subject: Re: [R] replace funcion > tabl > HI, > > Try this: > set.seed(1) > df1<-data.frame(colA=sample(1:100,n,replace=TRUE)) > > numbers1<-c(1,2,3,4,11,12) > numbers2<-c(5,6,7,8,9,10) > df1$colA[df1$colA%in%numbers1]<-"invierno" > df1$colA[df1$colA%in%numbers2]<-"verano" > head(df1,10) > colA > 1 27 > 2 38 > 3 58 > 4 91 > 5 21 > 6 90 > 7 95 > 8 67 > 9 63 > 10 verano > > A.K. > > > > ----- Original Message ----- > From: Dominic Roye <dominic.r...@gmail.com> > To: r-help@r-project.org > Cc: > Sent: Saturday, August 11, 2012 3:10 PM > Subject: [R] replace funcion > > Hello everybody, > > > I would like to replace or recode a list of numbers between 1 and 12 > (total > 100). I have tried to make it with recode, but i have two types of > replacements. For 1,2,3,4,11,12 => invierno and for 5,6,7,8,9 and 10 => > verano. > > recode(datos.mx1[,7], "1='invierno'; 2='invierno'; > 3='invierno';4='invierno';11='invierno';12='invierno'") #with this > command > it works perfectly, but i have only one part > > recode(datos.mx1[,7], "'5'='verano'; '6'='verano'; > '7'='verano';'8'='verano';'9'='verano';'10'='verano'") #when i run this > command it works also fine, but it clears the first change above. > > I had previously tried it with the if-command, but it doesn't work. I > hope > someone can help me. Thank you very much. > > Domi > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. > > > ______________________________________________ > R-help@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. ______________________________________________ R-help@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.