Graph of data -ProgrammingR header image
Beginner to advanced resources for the R programming language

Counting rows

This topic contains 6 replies, has 2 voices, and was last updated by  fidi 1 year, 6 months ago.

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

    fidi
    Member

    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?

    Thanks!

    Fidi

    #686

    bryan
    Member

    Fidi,

    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.

    #692

    fidi
    Member

    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 http://ftp.yalwa.org/cran/bin/windows/contrib/2.15
    Warning: can not access the repository index http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.15
    alerts:
    1: In open.connection (con, “r”):
    can not connect to ‘cran.r-project.org’ on port 80
    2: package ‘Doby’ is not available (for R version 2.15.1)

    Thanks for the help.
    Fidan

    #693

    bryan
    Member

    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.

    #702

    fidi
    Member

    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″ :( (((

     

    #703

    bryan
    Member

    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)

    #736

    fidi
    Member

    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.