R programming language resources › Forums › Data manipulation › Counting rows
- This topic has 6 replies, 2 voices, and was last updated 12 years, 7 months ago by
fidi.
- AuthorPosts
- September 14, 2012 at 8:59 am #646
fidi
MemberHi @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
September 17, 2012 at 2:44 am #686bryan
ParticipantFidi,
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.
September 18, 2012 at 8:00 am #692fidi
MemberHi 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.
FidanSeptember 18, 2012 at 12:15 pm #693bryan
ParticipantKeep 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.
September 19, 2012 at 9:04 am #702fidi
MemberHi 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” :((((
September 19, 2012 at 12:00 pm #703bryan
ParticipantThat’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)
September 26, 2012 at 12:35 pm #736fidi
MemberYes, i want to select all patients with for example C51.0, C51.1 and s.o.
Thank you! That’s the solution! 🙂 🙂 🙂
- AuthorPosts
- You must be logged in to reply to this topic.