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
381 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
105 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,150 points
120 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 5 in Data Analytics by anonymous
3,102 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,150 points
73 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,020 points
58 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
43 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
264 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
619 views