How do I sum the values of a variable by group but RETAIN all records

+1 vote

I have a data frame like this...

Ticker     Date            rec_count

 A            1/1/2019     1

A             2/1/2019     1

A             3/1/2019     1

B             1/1/2019     1

B             2/1/2019     1

B             3/1/2019     1

B             4/1/2019     1

And I basically want to create another variable SUM of the records, so that the new data table would retain all the records in the dataset and include the generated sum field.  Like this...

Ticker     Date            rec_count   sum_recs

 A            1/1/2019     1                 3

A             2/1/2019     1                 3

A             3/1/2019     1                 3

B             1/1/2019     1                 4

B             2/1/2019     1                 4

B             3/1/2019     1                 4

B             4/1/2019     1                 4

I have scoured the internet looking for a solution, but I cannot find one.  Please help!  I am new to R and while to some this may be an elementary question...it is absolutely driving me crazy!

Thanks!

Jun 4, 2019 in Data Analytics by Kirk
• 130 points
697 views

1 answer to this question.

0 votes

Hey @Kirk, what you can do is, edit your existing dataframe by creating a new column for the variable sum_rec. Something like this:

datframe$sum_rec <- (3,3,3,4,4,4,4)
answered Jun 6, 2019 by Kalgi
• 52,350 points

Related Questions In Data Analytics

0 votes
2 answers

How can I group a set of values by column using R programming?

Try this , Employee %>% group_by(EmpID) %>% mutate(SumSalary ...READ MORE

answered Aug 14, 2019 in Data Analytics by anonymous
813 views
+4 votes
3 answers

How to sum a variable by group in R?

You can also try this way, x_new = ...READ MORE

answered Aug 1, 2019 in Data Analytics by Cherukuri
• 33,030 points
78,148 views
0 votes
1 answer

How to write a custom function which will replace all the missing values in a vector with the mean of values in R?

Consider this vector: a<-c(1,2,3,NA,4,5,NA,NA) Write the function to impute ...READ MORE

answered Jul 4, 2018 in Data Analytics by CodingByHeart77
• 3,750 points
4,556 views
+1 vote
2 answers
0 votes
2 answers

What is difference between Distributed search head and Search head cluster?

 A distributed environment describes the separation of ...READ MORE

answered Dec 4, 2018 in Data Analytics by Ali
• 11,360 points
2,469 views
+2 votes
3 answers

Problem with installation of Wordcloud in anaconda

Using Anaconda Python 3.6 version For Windows ...READ MORE

answered Aug 7, 2018 in Data Analytics by Priyaj
• 58,020 points
18,689 views
0 votes
7 answers
0 votes
3 answers

How can I add YAML current date in rmarkdown ?

<$today:MM/dd/yyyy> READ MORE

answered Mar 25, 2019 in Data Analytics by Anupam Das
15,765 views
+1 vote
1 answer
0 votes
1 answer

How do I import document files in R programming

Try the following: read.table("~/SMSSpamCollection", header=TRUE, sep="\t") Change "~/" to the "ptah/to/your/file/" Mess around ...READ MORE

answered Nov 5, 2018 in Data Analytics by Kalgi
• 52,350 points
927 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP