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+s789695n4642756...@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@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.
______________________________________________
R-help@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.