It occurs to me a simple table command will do what you say you want but I suspect the real analysis is more complicated
dat1 <- data.frame(aa = sample(letters[1:5], 10, replace = TRUE), bb = 1:10) table(dat1$aa) On Tue, 21 Jul 2020 at 14:01, John Kane <jrkrid...@gmail.com> wrote: > As Bert says that does not look like R > > Have a look an these links for some suggestions on asking questions here. > > http://adv-r.had.co.nz/Reproducibility.html > > > http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example > > On Tue, 21 Jul 2020 at 13:42, Bert Gunter <bgunter.4...@gmail.com> wrote: > >> What language are you programming in? -- it certainly isn't R. >> >> I suggest that you stop what you're doing and go through an R tutorial or >> two before proceeding. This list cannot serve as a substitute for doing >> such homework (is this homework, btw? -- that's off topic here) nor can we >> provide such tutorials. >> >> I'm pretty sure the answer is quite simple, though it's a bit unclear as >> you did not provide a reprex (see the posting guide linked below for how >> to >> post here). However, I see no purpose in my blurting it out when you do >> not >> seem aware of even the most basic R constructs -- e.g. see ?while. Of >> course, others may disagree and provide you what you seek. >> >> >> Bert Gunter >> >> "The trouble with having an open mind is that people keep coming along and >> sticking things into it." >> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >> >> >> On Tue, Jul 21, 2020 at 10:21 AM e-mail ma015k3113 via R-help < >> r-help@r-project.org> wrote: >> >> > Dear All, I have a dataframe which has a few thousand companies with >> > unique company numbers and names and each company has data for several >> > years and each year is stored in a separate row. >> > >> > I want to get a total for the number of years of data for each company. >> > When I loop through the data with the following command I get a value >> of >> > ‘1’ rather than a total of the rows for each company >> > >> > All_companies$count <-0 >> > >> > while All_companies$COMPANY_NAME == All_companies$COMPANY_NAME + 1 >> > >> > + {All_companies$count=All_companies$count+1} >> > >> > Can you kindly help me on this? >> > >> > Ahson >> > [[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> > 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]] >> >> ______________________________________________ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. >> > > > -- > John Kane > Kingston ON Canada > -- John Kane Kingston ON Canada [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.