You can do this in 2 steps - have cut() make a factor with a different level for each time period then use levels<-() to merge some of the levels. > z <- cut(.5:3.5, breaks=c(0,1,2,3,4), labels=c("0-1", "1-2", "2-3", "3-4")) > levels(z) [1] "0-1" "1-2" "2-3" "3-4" > levels(z) <- c("between", "1-2", "between", "3-4") # or levels(z)[c(1,3)] <- "between" > str(z) Factor w/ 3 levels "between","1-2",..: 1 2 1 3
Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Dec 2, 2014 at 11:32 AM, Dries David <dries-da...@hotmail.com> wrote: > > > > Hey > > > I have a question about making a new variable in R. I have put my > dataset in attachment. I have to make a new variable "spits" where > spits=morning when uurenminuut (also a variabel) is between 5.30 and 9.30, > when uurenminuut is between 16.30 and 19.0 spits has to be equal to > evening. But here is my problem: for all the values not between 5.30- 9.30 > and 16.30-19.0 spits must be equal to "between" > > > > > > achtergrond$minuutdec=achtergrond$minuut/100 > > > achtergrond$uurenminuut=achtergrond$uur+achtergrond$minuutdec > > > > achtergrond$spits=cut(uurenminuut,c(-1.0,5.30,9.30,16.30,19.0,24.0),labels=c("between","morning","between","evening","between"),right=FALSE) > > > > > > When I do this i get a warning message, because I use between more > than once as label. Between has to be one label that covers all values that > are not in morning and evening. > > > > > > Could you help me with this? > > > > > > Kind regards > > > > > > Dries David > > > > > > > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.