[R] Searching from Dataframe.

David Winsemius dwinsemius at comcast.net
Tue Sep 11 09:22:14 CEST 2012


On Sep 11, 2012, at 12:11 AM, Rantony wrote:

> Hi,
> i have a dataframe containing some values.
> for eg:-
> 
> MyDataFrame<-
> Name   Age   Place
> -------    ------    -----------
> Aby          12        USA
> Raj            25        UK
> Romi        32        ENG
> Amy         31        IND
> 
> My requirement what is, i have a search key word[it should search from all
> the columns], that i need to find out from this dataframe. If search keyword
> found , it should return that particular row and column number.
> 
> For eg:- My search keyword is "ENG".
> After searching, it should return particular row & column number. Here it is
> " MyDataFrame[3,3] "

> which(MyDataFrame=="ENG", arr.ind=TRUE)
     row col
[1,]   3   3

You can certainly massage those values in any paste()y expression you choose.

--
David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list