Re: [R] how to break the loop using sapply?

2014-10-10 Thread Jeff Newmiller
Don't use apply functions if you want to do what you describe. They don't work that way. Use a while control structure. --- Jeff NewmillerThe . . Go Live...

[R] maximum likelihood estimation

2014-10-10 Thread pari hesabi
Hello,As an example for Exponential distribution the MLE is got by this structure:t - rexp(100, 2)loglik - function(theta){ log(theta) - theta*t}a - maxLik(loglik, start=1)print(a)Exponential distribution has a simple loglikelihood function. But if a new pdf has a more complicated form

Re: [R] how to break the loop using sapply?

2014-10-10 Thread PO SU
Is that mean while may be more effient than  for in R? as i know, while and for  are all just functions in R. Tks for your suggestion to not use apply that way, but i want to know, if possible, is there any way to break it ? Actually, there is a additional question:   x- c(3,4,5,6,9)  

Re: [R] Changing date format

2014-10-10 Thread Frederic Ntirenganya
Dear All, The following function gives me what I wanted. The input of function is one value and this push me to use sapply function to call it. Is there a better way of doing this? # day - function(x){ if(x== 60) { y =

Re: [R] how to break the loop using sapply?

2014-10-10 Thread Jeff Newmiller
Is it possible to break it? I already told you that... NO. Also your mention of efficiency is not relevant. Keep in mind that apply functions are not significantly faster than for loops or while loops. They are just compact ways to express your intent. Usually people having speed problems with

Re: [R] how to break the loop using sapply?

2014-10-10 Thread Hervé Pagès
Hi, On 10/09/2014 11:12 PM, PO SU wrote: Is that mean while may be more effient than for in R? as i know, while and for are all just functions in R. Tks for your suggestion to not use apply that way, but i want to know, if possible, is there any way to break it ? As Jeff said, you

[R] Bar plot in R with more than 2 factors

2014-10-10 Thread Franklin Mairura
Please help, it possible to make an r means barplot in R using base, where there are more than 2 factors and not with lattice, Franklin. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] how to break the loop using sapply?

2014-10-10 Thread PO SU
OK,  it  seems that i misunderstand something,  i forget how and when i pick up the monition in my mind that as possible as avoid using for loop. TKS for all your suggestions! But i still want the way to break sapply, if not exsits now, create it . such as:  sapply-function(...){ out-FALSE

Re: [R] Bar plot in R with more than 2 factors

2014-10-10 Thread Jim Lemon
On Thu, 9 Oct 2014 11:18:43 PM Franklin Mairura wrote: Please help, it possible to make an r means barplot in R using base, where there are more than 2 factors and not with lattice, Franklin. Hi Franklin, Have a look at the barNest function in the plotrix package. Jim

Re: [R] Changing date format

2014-10-10 Thread PIKAL Petr
Hi But It is not doing what you wanted. It does not extend 365 days year to 366 days. Instead it will incorrectly rename all days after 28th February in non leap years format(strptime(59, format = %j), %d-%b) [1] 28-II format(strptime(60, format = %j), %d-%b) [1] 01-III format(strptime(61,

[R] Count number of Fridays in a month

2014-10-10 Thread Abhinaba Roy
Hi R helpers, I want to write a function which will 1. Count the number of fridays in the current month ( to extract month from given date) and also the number of fridays in the preceeding month 2. Calculate the ratio of the number of fridays in current month to the number of fridays in the

Re: [R] Count number of Fridays in a month

2014-10-10 Thread Duncan Murdoch
On 10/10/2014, 7:28 AM, Abhinaba Roy wrote: Hi R helpers, I want to write a function which will 1. Count the number of fridays in the current month ( to extract month from given date) and also the number of fridays in the preceeding month 2. Calculate the ratio of the number of fridays

Re: [R] how to break the loop using sapply?

2014-10-10 Thread Jeff Newmiller
Doing as much as possible with vectors instead of loops of a good thing. Fooling yourself that apply functions are vectorized is, well, not a good thing. If you want to write a function to use instead of sapply, fine, but don't call it *apply because those functions always give you one result

Re: [R] Count number of Fridays in a month

2014-10-10 Thread Abhinaba Roy
Hi Duncan, I have converted the string to a POSIXIt object using strptime('31-may-2014',format=%d-%b-%Y) But could not figure out the way forward. Could you please elaborate a bit? On Fri, Oct 10, 2014 at 5:14 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/10/2014, 7:28 AM,

Re: [R] Count number of Fridays in a month

2014-10-10 Thread Duncan Murdoch
On 10/10/2014 8:10 AM, Abhinaba Roy wrote: Hi Duncan, I have converted the string to a POSIXIt object using strptime('31-may-2014',format=%d-%b-%Y) But could not figure out the way forward. Could you please elaborate a bit? Try this: ?POSIXlt Duncan Murdoch On Fri, Oct 10, 2014 at

Re: [R] Count number of Fridays in a month

2014-10-10 Thread Barry Rowlingson
Or try this: fridays - function(the_day){ require(lubridate) day(the_day) = 1 the_month = seq(the_day, the_day+months(1)-days(1),1) sum(wday(the_month) == 6) } That returns the number of Fridays in the month of a Date object given as arg: fridays(as.Date(2012-01-01)) [1] 4

Re: [R] maximum likelihood estimation

2014-10-10 Thread Arne Henningsen
On 10 October 2014 08:04, pari hesabi statistic...@hotmail.com wrote: Hello,As an example for Exponential distribution the MLE is got by this structure:t - rexp(100, 2)loglik - function(theta){ log(theta) - theta*t}a - maxLik(loglik, start=1)print(a)Exponential distribution has a simple

[R] (no subject)

2014-10-10 Thread Tasnuva Tabassum
I want to get rid of this thread. what to do? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html

Re: [R] (no subject)

2014-10-10 Thread Sven E. Templer
follow instructions on https://stat.ethz.ch/mailman/listinfo/r-help at To unsubscribe from R-help, get a password reminder, or change your subscription options enter your subscription email address: ... On 10 October 2014 16:16, Tasnuva Tabassum t.tasn...@gmail.com wrote: I want to get rid of

Re: [R] Changing date format

2014-10-10 Thread John McKown
On Fri, Oct 10, 2014 at 1:32 AM, Frederic Ntirenganya ntfr...@gmail.com wrote: Please try to not post in HTML. It is one of the forum rules. Dear All, The following function gives me what I wanted. The input of function is one value and this push me to use sapply function to call it. Is

[R] Maximum likelihood Estimation

2014-10-10 Thread Parvin Dehghani
maximum likelihood estimation pari hesabi 6:04 AM To: r-help@r-project.org Hello, As an example for Exponential distribution the MLE is got by this structure: t - rexp(100, 2) loglik - function(theta){ log(theta) - theta*t} a - maxLik(loglik, start=1) print(a) Exponential distribution has a

Re: [R] Count number of Fridays

2014-10-10 Thread jim holtman
Here is one way of doing it: require(lubridate) now - as.Date('2014-10-10') # some date # get first of month first_mon - now - day(now) + 1 # create sequence of days in the month so you can count Fridays x - seq(first_mon, by = '1 day', length = days_in_month(first_mon)) first_fri -

Re: [R] Count number of Fridays in a month

2014-10-10 Thread Gabor Grothendieck
On Fri, Oct 10, 2014 at 7:28 AM, Abhinaba Roy abhinabaro...@gmail.com wrote: Hi R helpers, I want to write a function which will 1. Count the number of fridays in the current month ( to extract month from given date) and also the number of fridays in the preceeding month 2. Calculate the

[R] How to remove the second line generated by addHeader function in the rtf package

2014-10-10 Thread Zhiqiu Hu
Dear friends, The addHeader function in the rtf package always generates two rows of texts even if a subtitle was not specified. Is there any way to stop the function from generating the second blank line? FYI, I cannot use the other functions, such as the addParagram and the addText, because

Re: [R] Count number of Fridays in a month

2014-10-10 Thread PO SU
In my Impression, there seems  exsits a function (let just call weekday) which can return a POSIXlt format date 's weekday. That means,  weekday( 31-may-2014 ) may return the right weekday maybe 5, so  a clumsy method is start to judge from 1-may-2014 to 31-may-2014 , you get  a vector x,

[R] errors in initial values in R2winBUGS

2014-10-10 Thread thanoon younis
Dear all R users I am trying to find the bayesian analysis using R2winBUGS but i have errors in initial values with two groups. the R-code #Initial values for the MCMC in WinBUGS init1-list(uby1=rep(0.0,10),lam1=c(0.0,0.0,0.0,0.0,0.0,0.0),