Back
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)
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))
library(dplyr)
new_df <- group_by(Name) %>% summarise(Years = sum(Age)), count = count(Name))
I think you mean:
library(dplyrdf <- data.frame(Name,Age) %>% group_by(Name) %>% summarise(Years = sum(Age, rm.na = TRUE), count = n())
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.
31k questions
32.8k answers
501 comments
693 users