r - Filter rows based on a threshold by grouping ID column -
i have data frame got from
id <- c("a","a","a","b","b","b","c","c","c") type <- c(45,46,47,45,46,47,45,46,47) point_a <- c(10,15,20,8,9,10,35,33,39) df <- data.frame(id,type,point_a) id type point_a 1 45 10 2 46 15 3 47 20 4 b 45 8 5 b 46 9 6 b 47 10 7 c 45 35 8 c 46 33 9 c 47 39 i want calculate median of point_a column grouping id , remove rows based on threshold.
for example, lets threshold 11. want remove rows grouped id having median less threshold , desired output
id type point_a 1 45 10 2 46 15 3 47 20 4 c 45 35 5 c 46 33 6 c 47 39 while able calculate medians not knowing how remove rows.
func <- function(x) (median(x,na.rm=true)) df1 <- df %>% group_by(id) %>% mutate_each(funs(.=func(.)),point_a) summarise(point_a = f(point_a)) kindly let me know how go doing this.
Comments
Post a Comment