Find the mean of y per grouped value of x

Hans

I have following problem: I have a data.frame with two columns. I will 'find the mean of y per grouped value of x'[formulation from hrbrmstr] . Example:

 x <- c(1,4,4,2,1,3,4,2,3,4)
 y <- c(2.23,5.56,5.53,3.32,2.32,4.21,5.60,3.43,4.32,5.59)
 my.data <- data.frame(x,y)   

> my.data
x    y
1  1 2.23
2  4 5.56
3  4 5.53
4  2 3.32
5  1 2.32
6  3 4.21
7  4 5.60
8  2 3.43
9  3 4.32
10 4 5.59

If I calculate it manually it is:

xx <- c(1,2,3,4)
yy <- c(mean(c(2.23,2.32)),mean(c(3.32,3.43)),mean(c(4.21,4.32)),mean(c(5.56,5.53,5.60,5.59)))
my.data.corr <- data.frame(xx,yy)

The result data.frame should be:

> my.data.corr
xx    yy
1  1 2.275
2  2 3.375
3  3 4.265
4  4 5.570

The order of xx in the result doesn't matter.

Thanks for your help!

hrbrmstr

If you're trying to find the mean of y per grouped value of x your example output is wrong.

 library(dplyr)

 my.data %>%
   group_by(x) %>%
   summarise(yy=mean(y))

##   x    yy
## 1 1 2.275
## 2 2 3.375
## 3 3 4.265
## 4 4 5.570

If you're trying to do something else, please re-phrase your question.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Javascript

Calculate mean max value per timeframe of array

From Dev

Find cells in dataframe where value is between x and y

From Dev

Sum of value per X grouped by Y

From Dev

Find minimum y value and its corresponding x value for each id

From Dev

Grouped boxplot with 2 y axes, 2 plotted variables per x tick

From Dev

PySpark fill missing/wrong value with grouped mean

From Dev

I have a plot and an Y value, need to find the X value

From Dev

Find y value for respective x from python plot (matplotlib)

From Dev

aproxfun function from binsmooth package, find x from y value

From Dev

Calculate percentage value of grouped value in geom_bar while showing count per grouped value

From Dev

Find the index of the first occurrence of some value that is not X or Y in a numpy array

From Dev

MATLAB: mean(X(Y == y, :));

From Dev

x and y key value pair must match, find in array

From Dev

Find a value from x axis that correspond to y axis in matplotlib python

From Dev

Dax - how to get average value per day where column x value is y?

From Dev

Pandas dataframe: Find location where value changes from x to y

From Dev

Make a function to find the value of Y according to X value

From Dev

R find the x and y value where the curve changes sharply

From Dev

Is there a method to find a Y value that is exceeded X % of the time in a time series?

From Dev

ggplot: barplot y value as grouped column value

From Dev

Python: Find Average Y-Value for Each X-Value in [X,Y] Coordinates

From Dev

Find a value y such (x < y) == (-x > -y) will be false, when x is a signed integer and x=1?

From Dev

Grouped boxplot with 2 y axes 2 variables per x tick

From Dev

Find the highest value of y for each x value and connect the points with a line

From Dev

sort value per group in already grouped dataframe

From Dev

Get all Elements where the first element grouped by 'X' property has 'Y' value not null

From Dev

Mutate a grouped value (like a conditional mean)

From Dev

How to find y value of interpolated spline at a desired x value?

From Dev

Filter first x number of grouped matches per column

Related Related

  1. 1

    Calculate mean max value per timeframe of array

  2. 2

    Find cells in dataframe where value is between x and y

  3. 3

    Sum of value per X grouped by Y

  4. 4

    Find minimum y value and its corresponding x value for each id

  5. 5

    Grouped boxplot with 2 y axes, 2 plotted variables per x tick

  6. 6

    PySpark fill missing/wrong value with grouped mean

  7. 7

    I have a plot and an Y value, need to find the X value

  8. 8

    Find y value for respective x from python plot (matplotlib)

  9. 9

    aproxfun function from binsmooth package, find x from y value

  10. 10

    Calculate percentage value of grouped value in geom_bar while showing count per grouped value

  11. 11

    Find the index of the first occurrence of some value that is not X or Y in a numpy array

  12. 12

    MATLAB: mean(X(Y == y, :));

  13. 13

    x and y key value pair must match, find in array

  14. 14

    Find a value from x axis that correspond to y axis in matplotlib python

  15. 15

    Dax - how to get average value per day where column x value is y?

  16. 16

    Pandas dataframe: Find location where value changes from x to y

  17. 17

    Make a function to find the value of Y according to X value

  18. 18

    R find the x and y value where the curve changes sharply

  19. 19

    Is there a method to find a Y value that is exceeded X % of the time in a time series?

  20. 20

    ggplot: barplot y value as grouped column value

  21. 21

    Python: Find Average Y-Value for Each X-Value in [X,Y] Coordinates

  22. 22

    Find a value y such (x < y) == (-x > -y) will be false, when x is a signed integer and x=1?

  23. 23

    Grouped boxplot with 2 y axes 2 variables per x tick

  24. 24

    Find the highest value of y for each x value and connect the points with a line

  25. 25

    sort value per group in already grouped dataframe

  26. 26

    Get all Elements where the first element grouped by 'X' property has 'Y' value not null

  27. 27

    Mutate a grouped value (like a conditional mean)

  28. 28

    How to find y value of interpolated spline at a desired x value?

  29. 29

    Filter first x number of grouped matches per column

HotTag

Archive