Dear all R users, Is there any function to omit repeated values in a vector? Your help will be highly appreciated. Thanks stat --------------------------------- Here’s a new way to find what you're looking for - Yahoo! Answers [[alternative HTML version deleted]]
?duplicated On 2/21/07, stat stat <stat700004@yahoo.co.in> wrote:> > Dear all R users, > > Is there any function to omit repeated values in a vector? Your help will > be highly appreciated. > > Thanks > stat > > > --------------------------------- > Here's a new way to find what you're looking for - Yahoo! Answers > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@stat.math.ethz.ch 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. > >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[alternative HTML version deleted]]
x <- sample(1:3, 20, TRUE) x # do you mean unique(x) # or rle(x)$values I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm Quoting stat stat <stat700004 at yahoo.co.in>:> Dear all R users, > > Is there any function to omit repeated values in a vector? Your > help will be highly appreciated. > > Thanks > stat > > > --------------------------------- > Here?s a new way to find what you're looking for - Yahoo! Answers > [[alternative HTML version deleted]] > >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Hi, 'unique' or its combination with 'match' if you need to keep the vector the same length will do it: > a<-c(1,2,4,2,5,5,6,7,8) > unique(a) [1] 1 2 4 5 6 7 8 > a[ which( is.na( match(1:length(a), match(unique(a),a)) ) ) ]=NA > a [1] 1 2 4 NA 5 NA 6 7 8 This is probably not the best implementation, but it does the job. 'table' will also give you the number of occurances of unique values: > a<-c(1,2,4,2,5,5,6,7,8) > table(a) a 1 2 4 5 6 7 8 1 2 1 2 1 1 1 Oleg stat stat wrote:> Dear all R users, > > Is there any function to omit repeated values in a vector? Your help will be highly appreciated. > > Thanks > stat > > > --------------------------------- > Here?s a new way to find what you're looking for - Yahoo! Answers > [[alternative HTML version deleted]] > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at stat.math.ethz.ch 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.-- Dr Oleg Sklyar * EBI/EMBL, Cambridge CB10 1SD, England * +44-1223-494466