Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (50.2k points)

I am having the following data-frame.

Name <- c("John","Mark","Ella","Mike","Zedd","John","Maria","Nick","John","Nick","Zedd","Andrea")

Age <- c(16,25,45,23,26,28,19,20,43,31,33,15)

df <- data.frame(Name,Age)

I want to group it by name and sum the years of age:

library(dplyr)

new_df <- group_by(Name) %>% summarise(Years = sum(Age)), count = count(Name))

1 Answer

0 votes
by (107k points)

I think you mean:

library(dplyr

df <- data.frame(Name,Age) %>% 

  group_by(Name) %>% 

  summarise(Years = sum(Age, rm.na = TRUE),

            count = n())

If you are a beginner and want to know more about R then do check out the following R programming tutorial that will help you in learning R programming from scratch. 

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...