Using dplyr package to summarise multiple columns - R

0 votes
my_data <- data.frame(
    w = sample(1:5, 10, replace = TRUE), 
    x = sample(1:5, 10, replace = TRUE), 
    y = sample(1:5, 10, replace = TRUE), 
    z = sample(1:5, 10, replace = TRUE), 
    my_group = sample(1:3, 10, replace = TRUE)
)

I would want to find the mean of each column within each group. i.e i'd want the mean of columns (w,x,y,z) with rescpect to the three different groups

Jun 6, 2018 in Data Analytics by zombie
• 3,790 points
1,909 views

1 answer to this question.

0 votes

'dplyr' package provides 'summarise_all()' function to apply to all the columns collectively:

my_data %>% group_by(my_group) %>% summarise_all(funs(mean))
answered Jun 6, 2018 by Bharani
• 4,660 points

Related Questions In Data Analytics

0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
2,019 views
0 votes
1 answer

R programming: Using Caret package to implement Random Forest

You can check out the official docs ...READ MORE

answered Apr 30, 2019 in Data Analytics by Tyrion anex
• 8,700 points
506 views
0 votes
1 answer

How to change y axis max in time series using R?

The axis limits are being set using ...READ MORE

answered Apr 3, 2018 in Data Analytics by Sahiti
• 6,370 points
3,538 views
0 votes
1 answer
0 votes
2 answers

How to use group by for multiple columns in dplyr, using string vector input in R?

data = data.frame(   zzz11def = sample(LETTERS[1:3], 100, replace=TRUE),   zbc123qws1 ...READ MORE

answered Aug 6, 2019 in Data Analytics by anonymous
13,677 views
0 votes
1 answer

How to group all columns exculding a single column?

You can either use group_by or group_by_at Using ...READ MORE

answered Apr 12, 2018 in Data Analytics by Sahiti
• 6,370 points
3,216 views
0 votes
1 answer

How to limit output of a dataframe in R?

For randomly sampling a row/cell where a ...READ MORE

answered Apr 18, 2018 in Data Analytics by kappa3010
• 2,090 points
2,910 views
0 votes
1 answer

Randomly subset of data with dplyr

Maybe this is what you want: # sample ...READ MORE

answered Jun 19, 2018 in Data Analytics by CodingByHeart77
• 3,740 points
663 views
0 votes
1 answer

Using "dplyr" to summarise multiple columns

You can use the "sumamrise_all()" function for ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
1,480 views
0 votes
1 answer

Unable to install the 'devtools' package in R

Run the below command in your Ubuntu/Linux ...READ MORE

answered Jun 6, 2018 in Data Analytics by Bharani
• 4,660 points
1,476 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