Hi, thanks for your suggestion. Indeed, this stops the error form occurring, but for some reason the 'probs = c(0.8)' input does not seem to be applied, as the same output is produced for the summarise command, despite changing the c() value. Is there any way of rectifying this? Thanks again!
Hi, I would like to keep rows that fall within the 80th percentile of the SF36PCS_HLEQ1 variable whilst discarding NA values so that the mean function will work. Thanks
I don't have your data, but using the iris dataset, the equivalent approach might look something like :
library(tidyverse)
# make an example dataset with some pesky NA values sprinkled in
spoiliris <- iris
spoiliris[1,1] <- NA
spoiliris[10,2] <- NA
spoiliris[101,3] <- NA
in step by step
# determine what the 80 percentile of sepal.length variable is
(q80 <- quantile(spoiliris$Sepal.Length,probs = 0.8,na.rm=TRUE))
#filter on the value
(spiris_within_q80 <- filter(spoiliris,
Sepal.Length <= q80))
#summarise the result
summarise(spiris_within_q80,
Petal.Width_mean = mean(Petal.Width,na.rm=TRUE))