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]]

