Dear R helpers Suppose I have a vector as vect1 = as.character(c("ABC", "XYZ", "LMN", "DEF"))> vect1[1] "ABC" "XYZ" "LMN" "DEF" I want to reverse the order of this vector as vect2 = c("DEF", "LMN", "XYZ", "ABC") Kindly guide Regards Vincy [[alternative HTML version deleted]]
On Tue, Mar 29, 2011 at 10:20 AM, Vincy Pyne <vincy_pyne at yahoo.ca> wrote:> Dear R helpers > > Suppose I have a vector as > > vect1 = as.character(c("ABC", "XYZ", "LMN", "DEF")) > >> vect1 > [1] "ABC" "XYZ" "LMN" "DEF" > > I want to reverse the order of this vector as > > vect2 = c("DEF", "LMN", "XYZ", "ABC")rev(vect1)> Kindly guide > > Regards > > Vincy > > > > > > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >
Hi Vincy, You can use the function rev().> rev(vect1)[1] "DEF" "LMN" "XYZ" "ABC" Also note that a simple google search for R and reverse would have lead you to this function. HTH, Josh On Tue, Mar 29, 2011 at 12:20 AM, Vincy Pyne <vincy_pyne at yahoo.ca> wrote:> Dear R helpers > > Suppose I have a vector as > > vect1 = as.character(c("ABC", "XYZ", "LMN", "DEF")) > >> vect1 > [1] "ABC" "XYZ" "LMN" "DEF" > > I want to reverse the order of this vector as > > vect2 = c("DEF", "LMN", "XYZ", "ABC") > > Kindly guide > > Regards > > Vincy > > > > > > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/
On Tue, Mar 29, 2011 at 12:20:50AM -0700, Vincy Pyne wrote:> > vect1 = as.character(c("ABC", "XYZ", "LMN", "DEF"))as.character is unnecessary, here.> > vect1 > [1] "ABC" "XYZ" "LMN" "DEF" > > I want to reverse the order of this vector as > > vect2 = c("DEF", "LMN", "XYZ", "ABC")vect2 <- rev(vect1)) cu Philipp -- Dr. Philipp Pagel Lehrstuhl f?r Genomorientierte Bioinformatik Technische Universit?t M?nchen Wissenschaftszentrum Weihenstephan Maximus-von-Imhof-Forum 3 85354 Freising, Germany http://webclu.bio.wzw.tum.de/~pagel/