Hello, Simple question that I am stuck on and can't seem to find an answer in the help files currently. I have a list which contains repeated ID's. I would like to have R count the number of ID's. For example: ID=c(1,1,1,1,2,2,2,2,3,3,3,3) as.data.frame(ID) Clearly, there are 3 groups. How would I have R give me the summary: ID 3 Many thanks, Charles [[alternative HTML version deleted]]
length(unique(ID)) Michael On Fri, May 25, 2012 at 11:38 AM, Charles Determan Jr <deter088 at umn.edu> wrote:> Hello, > > Simple question that I am stuck on and can't seem to find an answer in the > help files currently. ?I have a list which contains repeated ID's. ?I would > like to have R count the number of ID's. ?For example: > > ID=c(1,1,1,1,2,2,2,2,3,3,3,3) > as.data.frame(ID) > > Clearly, there are 3 groups. ?How would I have R give me the summary: > > ID > 3 > > Many thanks, > Charles > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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.
Hi. try using table function:> ID=c(1,1,1,1,2,2,2,2,3,3,3,3) > table(IF)ID 1 2 3 4 4 4 Also check ?tapply function Andrija On Fri, May 25, 2012 at 5:38 PM, Charles Determan Jr <deter088@umn.edu>wrote:> Hello, > > Simple question that I am stuck on and can't seem to find an answer in the > help files currently. I have a list which contains repeated ID's. I would > like to have R count the number of ID's. For example: > > ID=c(1,1,1,1,2,2,2,2,3,3,3,3) > as.data.frame(ID) > > Clearly, there are 3 groups. How would I have R give me the summary: > > ID > 3 > > Many thanks, > Charles > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > 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]]
That works if I want a count of each group but I needed a count of the number of groups. Michael answered that question with length(unique(ID)) However, this doesn't supply a title, it is just a number. I need it to still have the identifier 'ID'. Regards, Charles On Fri, May 25, 2012 at 11:50 AM, Steve Friedman <skfglades@gmail.com>wrote:> ?table > On May 25, 2012 11:46 AM, "Charles Determan Jr" <deter088@umn.edu> wrote: > >> Hello, >> >> Simple question that I am stuck on and can't seem to find an answer in the >> help files currently. I have a list which contains repeated ID's. I >> would >> like to have R count the number of ID's. For example: >> >> ID=c(1,1,1,1,2,2,2,2,3,3,3,3) >> as.data.frame(ID) >> >> Clearly, there are 3 groups. How would I have R give me the summary: >> >> ID >> 3 >> >> Many thanks, >> Charles >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help@r-project.org mailing list >> 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]]