basic query to make groups ..
1
0
Entering edit mode
ALok ▴ 170
@alok-2917
Last seen 9.6 years ago
Hi All, Sorry for one basic question. My vector contains two class of group elements, shown in different font and color x=c(*1.1, 1.2, 1.3*, 2.1, 2.2) I am trying to group the objects into two classes, as *1.1, 1.2, 1.3* and 2.1, 2.2 I can use command grep("^1.[12345678910]",x) [1] 1 2 3 > grep("^2.[12345678910]",x) [1] 4 5 but I am not able to automate it, using some variable k. I have many such cases, so I want to write a iterative loop for the structure using some variable k, for test case, lets assume k=1 grep("^k.[12345678910]",x) integer(0) Thanks in advance. Alok -- ************************************************************ Alok Kumar Srivastava Assistant Professor CRRao Advanced Institute of Mathematics, Statistics and Computer Science (AIMSCS) Gachibowli, Hyderabad 500046. ************************************************************ [[alternative HTML version deleted]]
• 1.0k views
ADD COMMENT
0
Entering edit mode
Devon Ryan ▴ 200
@devon-ryan-6054
Last seen 8.2 years ago
Germany
You're telling R that "k" is just a character in the grep pattern. Try: grep(sprintf("^%i.[0-9]",k), x)) -- Devon Ryan, Ph.D. Email: dpryan@dpryan.com Laboratory for Molecular and Cellular Cognition German Centre for Neurodegenerative Diseases (DZNE) Ludwig-Erhard-Allee 2 53175 Bonn Germany <devon.ryan@dzne.de> On Wed, Aug 7, 2013 at 11:26 AM, ALok <foralok@gmail.com> wrote: > Hi All, > Sorry for one basic question. My vector contains two class of group > elements, shown in different font and color > x=c(*1.1, 1.2, 1.3*, 2.1, 2.2) > I am trying to group the objects into two classes, as *1.1, 1.2, 1.3* and > 2.1, 2.2 > > I can use command > grep("^1.[12345678910]",x) > [1] 1 2 3 > > > grep("^2.[12345678910]",x) > [1] 4 5 > > but I am not able to automate it, using some variable k. > I have many such cases, so I want to write a iterative loop for the > structure using some variable k, > for test case, lets assume > > k=1 > grep("^k.[12345678910]",x) > integer(0) > > > Thanks in advance. > > Alok > > > > > -- > ************************************************************ > Alok Kumar Srivastava > Assistant Professor > CRRao Advanced Institute of Mathematics, Statistics and Computer Science > (AIMSCS) > Gachibowli, Hyderabad 500046. > ************************************************************ > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor@r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > [[alternative HTML version deleted]]
ADD COMMENT

Login before adding your answer.

Traffic: 704 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6