Can you say a little more about what you mean "it does not work"? I'd guess
you have a regular expression mistake and are probably getting more columns
than desired, but without an example, it's hard to be certain.

Use dput() and head() to give a small cut-and-paste-able example.

Michael

On Mon, Aug 22, 2011 at 10:33 AM, Jay <josip.2000@gmail.com> wrote:

> Hi,
>
> Let's say that I have a set of column names that begin with the string
> "Xyz". How do I extract these specific columns? I tried to do the
> following:
>
> dataframe1[,grep("Xyz",colnames(dataframe1))]
>
> But it does not work. What is wrong with my expression?
>
> ______________________________________________
> R-help@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.
>

	[[alternative HTML version deleted]]

