I should have mentioned that I do not know the number index of the columns,
but regardless, thanks for the responses

On Sat, Aug 11, 2012 at 10:46 PM, Ista Zahn <istazahn@gmail.com> wrote:

> Hi Sachin,
>
> There are at least two ways. The safer way is to use a regular
> expression to find the matching columns, like this:
>
> a <- initial_data[grep("^OFB[0-9]+", names(initial_data))]
>
> Alternatively, if you know that the columns you want are the first 8
> you can select them by position, like this:
>
> a <- initial_data[1:8]
>
> Best,
> Ista
>
> On Sat, Aug 11, 2012 at 7:59 AM, Sachinthaka Abeywardana
> <sachin.abeywardana@gmail.com> wrote:
> > Hi all,
> >
> > I have a data frame that has the columns OFB1, OFB2, OFB3,... OFB10.
> >
> > How do I select the first 8 columns efficiently without typing each and
> > every one of them. i.e. I want something like:
> >
> > a<-data.frame(initial_data$OFB1-10) #i know this is wrong, what would be
> > the correct syntax?
> >
> > Thanks,
> > Sachin
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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]]

