[R] Looping through a dataframe

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Tue Jul 21 19:41:47 CEST 2020

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 using 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 using 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]]

More information about the R-help mailing list