Re: [R] How to extract data.frame columns using regex?

2009-09-17 Thread Romain Francois
On 09/17/2009 12:04 PM, Martin Maechler wrote: "SH" == Schalk Heunis on Thu, 17 Sep 2009 11:15:16 +0200 writes: SH> I think this is what you want: >> df<- data.frame(x1=1:11,x2=2:12,x3=3:13,y=4:14) >> grep('^x',names(df)) SH> [1] 1 2 3 SH> The returned inde

Re: [R] How to extract data.frame columns using regex?

2009-09-17 Thread Martin Maechler
> "SH" == Schalk Heunis > on Thu, 17 Sep 2009 11:15:16 +0200 writes: SH> I think this is what you want: >> df <- data.frame(x1=1:11,x2=2:12,x3=3:13,y=4:14) >> grep('^x',names(df)) SH> [1] 1 2 3 SH> The returned indexes refer to the column positions, so you could d

Re: [R] How to extract data.frame columns using regex?

2009-09-17 Thread Schalk Heunis
I think this is what you want: > df <- data.frame(x1=1:11,x2=2:12,x3=3:13,y=4:14) > grep('^x',names(df)) [1] 1 2 3 The returned indexes refer to the column positions, so you could do: >names(df)[grep('^x',names(df))] [1] "x1" "x2" "x3" or >df[,grep('^x',names(df))] x1 x2 x3 1 1 2 3 2 2 3

[R] How to extract data.frame columns using regex?

2009-09-16 Thread Peng Yu
Hi, data.frame(x1=1:11,x2=2:12,x3=3:13,y=4:14) I want to extract all the columns that with the name 'x?'. Is there a general way to do this in R? Regards, Peng __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do