How to filter dataframe rows based on range of values

Hi, I am attempting to filter rows of my dataframe 'AGE' based on a range of values of the variable 'SF35PCS_HLEQ1', and then find the mean of the remaining 'AGE2' variable rows. However, I keep getting the same mean value output despite changing the range of values. How can I rectify this issue so that the range limitation command is effected?

AGE <- Full_data %>%
select(AGE2, SF36PCS_HLEQ1) %>%
filter(!, !<=100), !>=72)) %>%
summarise(AGE_mean = mean(AGE2)) %>%

Thanks in advance.

The comparisons <= and >= return TRUE or FALSE, both of which will satisfy the ! criterion. Try

AGE <- Full_data %>%
select(AGE2, SF36PCS_HLEQ1) %>%
filter(!, !, SF36PCS_HLEQ1<=100, SF36PCS_HLEQ1>=72) %>%
summarise(AGE_mean = mean(AGE2)) %>%

Hi, thank you for your suggestion. This method seems to work for some variables, and not for others. For instance, if I try and run the following code, I keep getting the same output for the mean of 'AGE', despite changing the cutoff for the 'DEMENTIA_COHORTDATE1' variable, suggesting that the 'DEMENTIA_COHORTDATE1 >=2004' command is not being applied:

AGE <- Full_data %>%
filter(!, AGE3>=55, !, !, DEMENTIA_COHORTDATE1>=2004)

Thanks again,

this bracket is unclosed

Hi, sorry, I made a typo there, I had included the bracket in the code but the issue still remains.

Please post the output of

tmp<- Full_data %>%

dput(head(tmp, 20))

Put a line with three back ticks just before and after the pasted output, like this
Your output here

check only has the one argument. It looks like you call it with 3 but not sure that is what you meant

1 2 3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.