Hi Lily, My suggestion should remove the underscore and everything after it, leaving just aClim and bClim in the ID column.
Best Ulrik On Sun, 3 Jul 2016, 20:34 lily li, <chocol...@gmail.com> wrote: > Hi Ulrik, > > Thanks. This is for one group, but how to do for several groups? I tried > gsub(c(),c(),df$ID), but it does not work. > > > On Sun, Jul 3, 2016 at 12:24 PM, Ulrik Stervbo <ulrik.ster...@gmail.com> > wrote: > >> Hi Lily, >> >> you can use gsub: >> >> df$ID <- gsub("_.*", "", df$ID) >> >> HTH >> Ulrik >> >> On Sun, 3 Jul 2016 at 20:16 lily li <chocol...@gmail.com> wrote: >> >>> I have a problem in changing row names in a dataframe in R. The first >>> column is ID, such as aClim_st02, aClim_st03, aClim_st 05, bClim_st01, >>> bClim_st02, etc. How to rename the names, so that aClim_ all grouped to >>> aClim, while bClim_ all grouped to bClim? Thanks for your help. >>> df >>> >>> ID temp precip LW SW >>> aClim_st02 >>> aClim_st03 >>> aClim_st05 >>> bClim_st01 >>> bClim_st02 >>> ... >>> >>> [[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. >>> >> > [[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.