Counting rows

This topic contains 6 replies, has 2 voices, and was last updated by  fidi 5 years, 8 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #646


    Hi @all!

    How can i count the rows of a data in r?

    For example i have the data “daten”, there are patients having different diseases and i want to know how many patients there are with kidney disease? Can i count the patient-id of patients with kidney disease an how can i do that?






    This is a job for the doBy package; specifically the summaryBy function. The code will be something like:

    summaryBy(~disease, data = daten, FUN = length)

    Repost if you have any problems.



    Hi Bryan,
    regrettably, i have a problem. I can’t install packages. I have translate the error message:

    > Install.packages (“Doby”)
    — Please select a CRAN mirror for this session — 
    Warning: can not access the repository index
    Warning: can not access the repository index
    1: In open.connection (con, “r”):
    can not connect to ‘’ on port 80
    2: package ‘Doby’ is not available (for R version 2.15.1)

    Thanks for the help.



    Keep in mind that R is case sensitive – I think your primary problem is that you’ve capitalized the “D” and not the “B” in “doBy”. But the warnings suggest that you might be having trouble with your internet connection as well. Checking/fixing those two things should fix it.



    Hi Bryan!

    I think it’s truly a problem with the internet connection. But i don’t need the doBy package anymore. Because I had try it with:

    summary((daten$TZE_D_LOK == “C61”), data = daten, FUN = length)

    –>daten is the data and TZE_D_LOK is the code of the localization of the disease

    Only problem is,  i can’t  use a placeholder with ==, for example i want to count all patients beginning with the code “^C51” :((((




    That’s true, the base summary function will work. I’ve gotten in the habit of using the doBy package because it has a few other functions that are helpful, too, but for a simple grouping what you have is fine.

    Do you mean you want to select cases where TZE_D_LOK begins with “^C51”, such as “^C51A”, “^C51B”, “^C51C”…?

    In that case you can use grep. This is untested, but something like this should work:

    summary(TZE_D_LOK, data = daten[grepl(pattern="^C51", x=daten$TZE_D_LOK, fixed=TRUE),], FUN = length)



    Yes, i want to select all patients with for example C51.0, C51.1 and s.o.

    Thank you! That’s the solution! 🙂 🙂 🙂

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.