[R] Sub-setting a data frame by partial column names?

Ivan Calandra ivan.calandra at uni-hamburg.de
Wed Nov 24 14:37:56 CET 2010


Hi,

I haven't followed, but I think you want something like:
subsetData<- bigData[ , c("Colname1", "Colname2", grep("partialName", 
colnames(bigData)))]

HTH,
Ivan

Le 11/24/2010 13:51, barah a écrit :
> Hi Sarah,
>
> Thanks a lot for the suggestion. It is working for me.
> subsetData<- bigData[,grep(partialName, colnames(bigData))]
>
>
> But if i want to extract multiple columns along with the columns with
> similar names, how do i that? Say the others column have similar values for
> all the columns with similar partialnames. I tried the following
>
> subsetData<- bigData[,grep("partialName", "Colname1", "Colname2",
> colnames(bigData))]
>
> It did not work.
> Do you have any suggestion ?
>
> Regards,
>
> Pankaj Barah
>

-- 
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calandra at uni-hamburg.de

**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php



More information about the R-help mailing list