[R] Looping thorugh dataframe
e-mail ma015k3113
m@015k3113 @end|ng |rom b|ueyonder@co@uk
Wed Jul 22 16:04:52 CEST 2020
Bert, thanks for responding to my email. I do realise that newbie's like my can expect curt answers but not to worry. I am definitely learning 'R' and what I posted are also statements from R. The statements run perfectly well but don't do what I want them to do. My mistake I have posted sample data. Here is the data:
COMPANY_NUMBER COMPANY_NAME YEAR_END_DATE Turnover
22705 AA 30/09/10 420,000
22705 AA 30/09/09 406,000
113560 BB 30/06/19 474,000
192761 CC 31/01/19 796,000
192761 CC 31/01/18 909,000
192761 CC 31/01/17 788,000
5625107 DD 30/06/19 3,254,002
5625107 DD 30/06/18 1,840,436
All_companies$count <-0
while All_companies$COMPANY_NAME == All_companies$COMPANY_NAME + 1
+ {All_companies$count=All_companies$count+1}
I want to find out many times each company has appeared in the dataframe and the average of the turnover for the years. Like company AA appears twice and average turnover is 413,000.
'All_companies' is the name of the dataframe.
In the end apologies for not being more clear the first time around and of course many thanks for your help in advance.
Kind regards
Ahson
On 21 July 2020 at 18:41 Bert Gunter <bgunter.4567 using 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 )
More information about the R-help
mailing list