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,770 points
1,124 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,580 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
991 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 29, 2019 in Data Analytics by Tyrion anex
• 8,560 points
82 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,320 points
1,069 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, 2019 in Data Analytics by anonymous
8,363 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,320 points
1,471 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
243 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,720 points
155 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,580 points
909 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,580 points
1,001 views