Calculate mean with a filter on a column's values

mql4beginner

I've created this small data frame:

employee <- c('Yossi ','Pitt ','Deepak','Golan')
salary <- c(21000, 23400, 26800,91000)
testd <- data.frame(employee,salary)

When I write:

mean(testd$salary) 

I get the right answer : 40550

But when I tried to calculate the mean for salaries that are greater than 25000 I get this outcome.

mean(testd$salary>=25000)
# [1] 0.5

and not 58900 that is made of this calculation: (26800+91000)/2

What have I done wrong?

Nishanth

Try:

mean(testd$salary[testd$salary>=25000])

Actually testd$salary>=25000 is a vector of boolean values, which are automatically mapped to numeric type (True = 1, False = 0) when you call mean.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calculate mean for reocurring observations of one column but with differing values of other column

From Java

How to calculate mean values grouped on another column in Pandas

From Dev

Calculate the mean of several values within the same row in a column

From Dev

How to calculate mean value of values on column which go comma?

From Dev

Calculate mean of calculated values

From Dev

Calculate mean difference values

From Dev

Calculate the mean of values in a loop

From Dev

PySpark - Split/Filter DataFrame by column's values

From Dev

Calculate mean/median of values in a column based on dates of another column using Python

From Dev

How to calculate mean values per values in other column in one PROC SQL query in SAS Enterprise Guide?

From Dev

Calculate the mean values if the numbers are same

From Dev

fill the filter values of a column by it's own values in kendo

From Dev

Get mean values per sample, arranged by another column of ID's

From Dev

How to get mean of rows selected with another column's values in pandas

From Dev

How to get mean of selected rows with another column's values in pandas

From Dev

Calculate mean of column based on another column

From Dev

Calculate column mean on single column in a database

From Dev

calculate the mean of column and also the comments in next column

From Python

Calculate column-wise mean of rows of a numpy matrix selected using values from another array

From Dev

Is there any package in pandas to calculate mean of selected part of values of column based on other columns

From Dev

Converting a column in a data.frame to numeric type to calculate mean values in R

From Dev

Mean of values in a column for unique values in another column

From Dev

Replace the values of one column with the mean of values of this column

From Dev

in R, how to calculate mean of all column, by group?

From Dev

How to calculate rolling mean for each column

From Dev

How to calculate the mean for a column subsetted from the data

From Dev

Pandas - calculate mean and add value in new column

From Dev

How to calculate the mean value of the column inside the function

From Java

Calculate new column as the mean of other columns pandas

Related Related

  1. 1

    Calculate mean for reocurring observations of one column but with differing values of other column

  2. 2

    How to calculate mean values grouped on another column in Pandas

  3. 3

    Calculate the mean of several values within the same row in a column

  4. 4

    How to calculate mean value of values on column which go comma?

  5. 5

    Calculate mean of calculated values

  6. 6

    Calculate mean difference values

  7. 7

    Calculate the mean of values in a loop

  8. 8

    PySpark - Split/Filter DataFrame by column's values

  9. 9

    Calculate mean/median of values in a column based on dates of another column using Python

  10. 10

    How to calculate mean values per values in other column in one PROC SQL query in SAS Enterprise Guide?

  11. 11

    Calculate the mean values if the numbers are same

  12. 12

    fill the filter values of a column by it's own values in kendo

  13. 13

    Get mean values per sample, arranged by another column of ID's

  14. 14

    How to get mean of rows selected with another column's values in pandas

  15. 15

    How to get mean of selected rows with another column's values in pandas

  16. 16

    Calculate mean of column based on another column

  17. 17

    Calculate column mean on single column in a database

  18. 18

    calculate the mean of column and also the comments in next column

  19. 19

    Calculate column-wise mean of rows of a numpy matrix selected using values from another array

  20. 20

    Is there any package in pandas to calculate mean of selected part of values of column based on other columns

  21. 21

    Converting a column in a data.frame to numeric type to calculate mean values in R

  22. 22

    Mean of values in a column for unique values in another column

  23. 23

    Replace the values of one column with the mean of values of this column

  24. 24

    in R, how to calculate mean of all column, by group?

  25. 25

    How to calculate rolling mean for each column

  26. 26

    How to calculate the mean for a column subsetted from the data

  27. 27

    Pandas - calculate mean and add value in new column

  28. 28

    How to calculate the mean value of the column inside the function

  29. 29

    Calculate new column as the mean of other columns pandas

HotTag

Archive