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,690 points
202 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,550 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,700 points
63 views
0 votes
1 answer
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 darklord
• 6,140 points
69 views
0 votes
1 answer
0 votes
1 answer

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

dplyr added versions for group_by. This allows you ...READ MORE

answered Apr 12, 2018 in Data Analytics by CodingByHeart77
• 3,680 points

edited Apr 12, 2018 by CodingByHeart77 2,239 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 darklord
• 6,140 points
37 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,010 points
32 views
0 votes
1 answer

Randomly subset of data with dplyr

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

answered Jun 18, 2018 in Data Analytics by CodingByHeart77
• 3,680 points
22 views
0 votes
1 answer

Using "dplyr" to summarise multiple columns

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

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,550 points
118 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,550 points
474 views