Dinesh Kumar V
Dinesh Kumar V

Reputation: 33

Group by Help in R and Keeping all columns

I have a large dataset with 4161512 rows and 10 columns. I am trying to group my dataset based on two columns which are character data type.I could make the grouping but I get only three rows as output, I looking for other 7 columns also which are related to grouped by columns.

Below code which gives me only the three columns (Manufacture, Name, Pay) but I also want other 7 column so that I can have 10 columns in my data table including the grouped columns.

Newname = Dt %>% 
  group_by(Manufacturer,Name) %>% 
  summarise(Payments=sum(Payments))

Please help Thank you in advance!

Upvotes: 3

Views: 3792

Answers (1)

Wietze314
Wietze314

Reputation: 6020

Use mutate instead of summarise after grouping the data

Newname = Dt %>% 
  group_by(Manufacturer,Name) %>% 
  mutate(PaymentsSum = sum(Payments))

Upvotes: 5

Related Questions