[R] Search for Matching word in a Dataframe
Pascal Oettli
kridox at ymail.com
Thu Jun 13 09:37:45 CEST 2013
Hello,
?grep
> grep('ARUN', MyDat$NAME)
[1] 2
Regards,
Pascal
On 13/06/13 16:08, R_Antony wrote:
> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> 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