Are the data in a data frame? Is it the first letter of the id that defines unique ID's or something else?
Depending on your answers: ?substring ?table ?with may be useful, as in with(yourdata,table(substring(ID,1,1))) ... or not, if you meant something else. -- Bert On Tue, Oct 23, 2012 at 12:14 PM, farnoosh sheikhi <farnoosh...@yahoo.com> wrote: > Hello, > > I have a data as follow: > ID Visit > xa1 > xa2 > yb1 > yc23 > yb33 > > I want to look at frequency of visit for ID and create a new column as > response . > For example my response would be 2 for x and 3 for y. > I think I need to write a loop, but I don't know how. > I really appreciate your help. > Thanks a lot. > Best,Farnoosh Sheikhi > [[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. > -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm ______________________________________________ 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.