[R] Search for Matching word in a Dataframe

R_Antony antony.akkara at ge.com
Thu Jun 13 09:08:54 CEST 2013


Hi

Here i have a dataframe called MyDat.

MyDat<- data.frame(NAME = c("ANTONY001", "ARUN002", "AKBAR003", 
"JONATHAN004", "PETER005", "AVATAR006", "YULIJIE007", "RAM008", 
"DESILVA009"), 
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.
Antony.



--
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.



More information about the R-help mailing list