Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9322561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:07:17+00:00 2026-06-19T04:07:17+00:00

This might be very trivial but I could not find an easy solution anywhere.

  • 0

This might be very trivial but I could not find an easy solution anywhere. I am trying to create a script in R to count entries in one column that belong to a one of 3 categories specified another column. I have a list of clinical patients with ID numbers (more than one entry for the same ID) that have been seen by two services (a or b). I need to know how many ID have been seen by service a and by service b and service c, but counting repeated visits by a service only once (so basically the number of patients that have used each service at least once) – hope this makes sense, here is an example to explain.

Example:


ID Category
A001 a
A002 a
A002 a
A002 b
A003 b
A003 b
A005 c
A001 a
A004 b
A004 b
A006 c
A006 a

Output should be something like:

     a=3
     b=3
     c=2

This is what I have done, but I am quite stuck, and this might not be good at all!

 DataString<- matrix(nrow=dim(refnum)[1], ncol=1)
 for (i in 1:dim(refnum)[1]){
   DataString[i,1]<- paste(refnum[i,], collapse = '')
 }

 #generate vector of unique strings
 uniqueID<- unique(DataString)

 #create new matrix to store new IDs
 newID<- matrix(nrow=dim(data)[1], ncol=1)

 #initiate index n
 n<-0
 #loop through unique strings
 for (i in 1:dim(refnum)[1]){
   #increment n by 1 for each increment through unique strings
   n<- n+1
   #loop through data rows
   for (j in 1:dim(data)[1]){    
     #find matches with string i
     index<- which(DataString == uniqueID[i,1])
     #assign new ID to matching rows
     newID[index,1]<- n
   }
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T04:07:19+00:00Added an answer on June 19, 2026 at 4:07 am

    One of the many solutions:

    table(df[!duplicated(df), "Category"])
    
    # a b c 
    # 3 3 2 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this might be a very simple question, but I could not find an answer
This might have very obvious solution but I'm afraid I cannot find out how
This might very well be very stupid question, but I can not find QTabBar
This might be a very newbie question, but I didn't find anything satisfying I
I know, this might be a very basic question but I am not 100%
This might seem like a very easy question for some of you folks, but
This might be very trivial, but I haven't found an answer yet (and I'm
This might be a very simple question for you, but I'm stumped. I'm trying
This might be a very basic question but I'm trying to understand this behavior
This might be very easy for some of you but very hard for me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.