[R] searching for a specific row name in R

MacQueen, Don m@cqueen1 @end|ng |rom ||n|@gov
Thu Aug 16 01:38:58 CEST 2018


It depends on what you want to check. There are a lot of things you can check without looping.

For example, if you want to check whether all of the first letters of the identifier names are "A", you could do
  table( substr(idnames,1,1))
to show you all of the first letters, and how many there are of each.

Like Bert said, some tutorials would be good. Even better would be to find someone nearby who knows R really well. I think R is probably difficult to learn all on one's own.

Small suggestion: be careful about using the word "list" in statements like "a list of identifier names".  It's ok in ordinary English, but in R a "list" is a special kind of data structure. Better to say "a vector of identifier names".

-Don

--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509



From: Deepa <deepamahm.iisc using gmail.com>
Date: Monday, August 13, 2018 at 8:36 PM
To: "MacQueen, Don" <macqueen1 using llnl.gov>, array R-help <r-help using r-project.org>
Subject: Re: [R] searching for a specific row name in R

Hi Don,

When there is a list of identifier names that I want to check, the only way is to loop over each entry stored in the list of identifier names or is there is there any other shortcut?

Many thanks for the response?

On Mon, Aug 13, 2018 at 8:18 PM, MacQueen, Don <macqueen1 using llnl.gov<mailto:macqueen1 using llnl.gov>> wrote:
Or to return a logical value, i.e., TRUE if the column contains the value, FALSE if it does not:

  any( x[,2] == 'A501' )

-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509



On 8/13/18, 12:09 AM, "R-help on behalf of Albrecht Kauffmann" <r-help-bounces using r-project.org<mailto:r-help-bounces using r-project.org> on behalf of alkauffm using fastmail.fm<mailto:alkauffm using fastmail.fm>> wrote:

    Hello Deepa,

    sum(x[,2] == "A501")
    or
    which(x[,2] == "A501")
    .
    Best,
    Albrecht


    --
      Albrecht Kauffmann
      alkauffm using fastmail.fm<mailto:alkauffm using fastmail.fm>

    Am Mo, 13. Aug 2018, um 07:10, schrieb Deepa Maheshvare:
    > Hello Everyone,
    >
    > I have a 1000 x 20 matrix. The second column of the matrix has the names
    > of identifiers. How do I check when a certain identifier is present in
    > the set of 1000 identifier names present in the second column. For
    > instance, let the names of identifiers be A1,A2,...A1000. I want to
    > check whether A501 is present .How can this be checked?
    >
    > Any help will be highly appreciated.
    >
    >
    >   [[alternative HTML version deleted]]
    >
    > ______________________________________________
    > R-help using r-project.org<mailto:R-help using r-project.org> mailing list -- To UNSUBSCRIBE and more, see
    > 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 using r-project.org<mailto:R-help using r-project.org> mailing list -- To UNSUBSCRIBE and more, see
    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.



	[[alternative HTML version deleted]]



More information about the R-help mailing list