Thanks for your reply. Let me make an example then:
m<- c(150, 400, 500,750,800, NA) How can I use cut to generate the m_group as c(0,0.4755,1, 0.2275,0,0): Breaks 331.04 476.07 608.66 791.5 NA m_group 0 x 1 x 0 0 Thank you very much! Regards, Yan -----Original Message----- From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] Sent: Tuesday, October 18, 2011 5:23 AM To: Li, Yan Cc: r-help@r-project.org Subject: Re: [R] cut data into sevral group and assign calculated values individually On 17.10.2011 20:53, Li, Yan wrote: > Hi All, > > I have some data from which I set four points to be breaks. Based on these > points, I cut the dataset into four groups and assign a number to it: > > <=331.04 assign 0 >> 331.04<=476.07 assign data-331.04/(476.07-331.04) >> 476.07<=608.66 assign 1 >> 608.66<=791.5 assign 791.5- data/(791.5-608.66) >> 791.5 and NA assign 0 > > > Breaks 331.04 476.07 608.66 791.5 > NA > m_group 0 x 1 x > 0 0 > > > I can use cut() to group the data according to the breaks but having > difficulty to assign the two calculated interval values. > Based on the levels of the factor resulted by cut(), you can calculate a new vector easily. But since you have not specified a reproducible example, I cannot quickly change it in order to show how it works. Best, Uwe Ligges > Thank you very much! > > Regards, > Yan > > [[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.