Re: [R] extract columns from a dataframe

From: Sean Davis <sdavis2_at_mail.nih.gov>
Date: Mon 05 Jul 2004 - 23:04:06 EST


Rado,

If you have a data.frame df like:

Col1 Col2 Col3 Col4
1 2 A B

Then you should be able to do:

df[,c("Col2","Col4")]

to get the second and fourth columns.

Sean

On 7/5/04 8:53 AM, "Rado Bonk" <rado.bonk@jrc.it> wrote:

> Dear R users,
>
> I'm coming back to R after while. I have a data frame with 200 columns,
> each column has a name. How to extract all columns to a new dataset, but
> the specified (by names) ones?
>
> I was playing with that for a little bit using the vector syntax but got
> several syntax errors.
>
>
> Thanks,
>
> Rado
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 05 23:06:35 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:41 EST