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] " Can anyone help me please ? - Antony. -- View this message in context: http://r.789695.n4.nabble.com/Searching-from-Dataframe-tp4642722.html Sent from the R help mailing list archive at Nabble.com.
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
And how to get the vector from a list if the list item found inside ? for eg:- MyList<- c("US","UK","UAE") Here i want to check a list item UAE which is in 3rd row. How i will get that row position ? - Thanks in advance Antony -- View this message in context: http://r.789695.n4.nabble.com/Searching-from-Dataframe-tp4642722p4642744.html Sent from the R help mailing list archive at Nabble.com.
How can I get index from a list if I know the listitem ? For eg:- Mylist<-c("A","B","C") Acually,Here I need to get the index of "B" as 2. From: arun kirshna [via R] [mailto:ml-node+s789695n4642756h74@n4.nabble.com] Sent: Tuesday, September 11, 2012 5:56 PM To: Akkara, Antony (GE Energy, Non-GE) Subject: Re: Searching from Dataframe. Hi, You can try this also: df1<-read.table(text=" Name Age Place Aby 12 USA Raj 25 UK Romi 32 ENG Amy 31 IND ",sep="",header=TRUE,stringsAsFactor=FALSE) #row index unlist(apply(df1,1,function(x) which(grepl("ENG",x)))) #[1] 3 #column index unlist(apply(df1,2,function(x) which(grepl("ENG",x)))) #Place # 3 #or, you can use arrayInd(which(df1=="ENG"), dim(df1)) # [,1] [,2] #[1,] 3 3 #or df2<-as.matrix(df1) arrayInd(which(grepl("ENG",df2)), dim(df2)) # [,1] [,2] #[1,] 3 3 A.K. ________________________________ If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Searching-from-Dataframe-tp4642722p4642756 .html To unsubscribe from Searching from Dataframe., click here <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscrib e_by_code&node=4642722&code=YW50b255LmFra2FyYUBnZS5jb218NDY0MjcyMnwxNTUx OTQzMDI5> . NAML <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_view er&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.Bas icNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.tem plate.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml -instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemai l.naml> -- View this message in context: http://r.789695.n4.nabble.com/Searching-from-Dataframe-tp4642722p4642758.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Hello, Try which("B" == Mylist) Hope this helps, Rui Barradas Em 11-09-2012 13:31, Rantony escreveu:> How can I get index from a list if I know the listitem ? > > For eg:- Mylist<-c("A","B","C") > > Acually,Here I need to get the index of "B" as 2. > > > > From: arun kirshna [via R] > [mailto:ml-node+s789695n4642756h74 at n4.nabble.com] > Sent: Tuesday, September 11, 2012 5:56 PM > To: Akkara, Antony (GE Energy, Non-GE) > Subject: Re: Searching from Dataframe. > > > > Hi, > You can try this also: > df1<-read.table(text=" > Name Age Place > Aby 12 USA > Raj 25 UK > Romi 32 ENG > Amy 31 IND > ",sep="",header=TRUE,stringsAsFactor=FALSE) > > #row index > unlist(apply(df1,1,function(x) which(grepl("ENG",x)))) > #[1] 3 > #column index > unlist(apply(df1,2,function(x) which(grepl("ENG",x)))) > #Place > # 3 > #or, you can use > arrayInd(which(df1=="ENG"), dim(df1)) > # [,1] [,2] > #[1,] 3 3 > #or > df2<-as.matrix(df1) > arrayInd(which(grepl("ENG",df2)), dim(df2)) > # [,1] [,2] > #[1,] 3 3 > > A.K. > > ________________________________ > > If you reply to this email, your message will be added to the discussion > below: > > http://r.789695.n4.nabble.com/Searching-from-Dataframe-tp4642722p4642756 > .html > > To unsubscribe from Searching from Dataframe., click here > <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscrib > e_by_code&node=4642722&code=YW50b255LmFra2FyYUBnZS5jb218NDY0MjcyMnwxNTUx > OTQzMDI5> . > NAML > <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_view > er&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.Bas > icNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.tem > plate.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml > -instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemai > l.naml> > > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Searching-from-Dataframe-tp4642722p4642758.html > Sent from the R help mailing list archive at Nabble.com. > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
Have you read "An Introduction to R" (ships with every copy of R) where these sorts of questions are answered? There are other R tutorials on the web also, if you look. -- Bert On Tue, Sep 11, 2012 at 3:59 AM, Rantony <antony.akkara at ge.com> wrote:> And how to get the vector from a list if the list item found inside ? > for eg:- MyList<- c("US","UK","UAE") > Here i want to check a list item UAE which is in 3rd row. > How i will get that row position ? > > - Thanks in advance > Antony > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Searching-from-Dataframe-tp4642722p4642744.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.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm