Re: [R] need help in customising function in stat_summary function ggplot2

2016-10-21 Thread Indhira, Anusha
Thanks mark for pointing out my mistake and suggestion.I can get desired output now -Original Message- From: Mark Sharp [mailto:msh...@txbiomed.org] Sent: 20 October 2016 17:21 To: Indhira, Anusha Cc: r-help@r-project.org Subject: Re: [R] need help in customising function in

Re: [R] need help in customising function in stat_summary function ggplot2

2016-10-20 Thread Mark Sharp
Indhira, You have to assign cnt and new value in the loop if you want it to update in the loop. However, to count the number of values of x > median(x), there are multiple options. You are using a loop where none is needed in R, which has many implicit vector functions that run with relational

Re: [R] need help in customising function in stat_summary function ggplot2

2016-10-20 Thread William Dunlap via R-help
Your code, cnt = 0 for(i in 1:length(x)){ ifelse(x[i] > median(x),cnt+1,cnt) } sets cnt to zero and never sets it to anything else. Hence it is zero at the end of the loop. if you set cnt to the value of your call to ifelse you should get the desired result cnt <- ifelse(x[i] > media

Re: [R] need help in customising function in stat_summary function ggplot2

2016-10-20 Thread David L Carlson
You do know that the median is defined as the point with half the values above it and half below it? For even sample sizes it will always be 50%. Your function is not working because you used the ifelse() function instead of the programming command if() else: > ?Control # Note the capital "C" >