[R] Search for Matching word in a Dataframe

arun smartpink111 at yahoo.com
Thu Jun 13 15:22:31 CEST 2013

You could use:
#[1] 2
#[1] 2
#[1]  2 10 11

----- Original Message -----
From: R_Antony <antony.akkara at ge.com>
To: r-help at r-project.org
Sent: Thursday, June 13, 2013 3:08 AM
Subject: [R] Search for Matching word in a Dataframe


Here i have a dataframe called MyDat.

MyDat<- data.frame(NAME = c("ANTONY001", "ARUN002", "AKBAR003", 
"JONATHAN004", "PETER005", "AVATAR006", "YULIJIE007", "RAM008", 
COL_A = c(0, 0, 0, 1, 0, 1, 2, 3, 1), 
COL_B = c(0, 3, 0, 3, 3, 1, 0, 1, 2), 
COL_C = c(1, 2, 3, 1, 2, 3, 1, 2, 3), stringsAsFactors=FALSE) 

and here my requirement what is, i need to get the row number, where the
NAME column matches with selection criteria.

For eg:- If i give NAME = "ARUN", It should select row no: 2 where 
"ARUN002" comes.

i tried with this way 
nRow<-which("ARUN"==MyDat[,1]) - But here, the row number will select only
the NAME column value match exactly, otherwise it wont select.

My requirment is, it should select the row number(s), where the searching
word should match atleast. Exact match is not compulsory.

- Thanks in Advance.

View this message in context: http://r.789695.n4.nabble.com/Search-for-Matching-word-in-a-Dataframe-tp4669426.html
Sent from the R help mailing list archive at Nabble.com.

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list