[R] Help with a for complex for loop that looks into another data frame

2014-11-07 Thread Yan Wu
Hello everyone!

I am working on a stock trading algorithm. I have created a data frame with
the stocks, and a summary data frame, master_df_ex, and master_df_ex_sum,
respectively.

The goal is to create something each day that has equal long and shorts,
and thus for each day, the sum of the ls_flag = 0.

For master_df_ex, there is a rank by strength of magnitude column, up or
down column, then a long or short column.

The ls_flag is set by the updn_flag for the stocks that are ranked in the
top half (in this case, since we have 4 per day, rank = 1 and rank = 2 are
set by updn_flag.

*I need to create a process to fill in the NA's in the ls_flag.*

My thinking is to create a summary table, where i run a summary,replace the
contents, until both the NA are 0 and the sum of the ls_flag =0.

For example, here is the current data:

asof_dt<-rep(seq(as.Date("2014-10-01"), as.Date("2014-10-03"), "days"),4)

rank_mag<-(rep(seq(1,4),3))

updn_flag<-c(-1,-1,-1,1,-1,-1,1,1,-1,1,-1,-1)

ls_flag<-c(-1,-1,NA,NA,-1,-1,NA,NA,-1,1,NA,NA)

master_df_ex<-data.frame(asof_dt,rank_mag,updn_flag,ls_flag)

master_df_ex<-arrange(master_df_ex,asof_dt,rank_mag)

master_df_ex_sum<-summarise(master_df,tot_flag = sum(ls_flag, na.rm = TRUE),

tot_NA = sum(is.na(ls_flag)))

> master_df_ex

  asof_dt rank_mag updn_flag ls_flag

1  2014-10-011-1  -1

2  2014-10-012 1   1

3  2014-10-013 1  NA

4  2014-10-014 1  NA

5  2014-10-021-1  -1

6  2014-10-022-1  -1

7  2014-10-023-1  NA

8  2014-10-024 1  NA

9  2014-10-031 1   1

10 2014-10-032 1   1

11 2014-10-033 1  NA

12 2014-10-034-1  NA

> master_df_ex_sum

Source: local data frame [3 x 3]


 asof_dt tot_flag tot_NA

1 2014-10-010  2

2 2014-10-02   -2  2

3 2014-10-032  2

For 2014-10-02, since the the tot_flag = -2, the NA's for this date should
both be -1

For 2014-10-03, since the tot_flag = 2, the NA's should both be -1

For 2014-10-01 (hardest one):

The logic should look at 2014-10-01 in master_df_ex_sum, since tot_NA is
not 0, go into master_df_ex and find the lowest rank by rank_mag where
ls_flag is NA. Assign ls_flag = 1.

Then run the summary again, the NAs will be 1, and the sum of ls_flag will
be 1.

Then it should go into master_df_ex again, and assign a -1 to line 4. Then
the summary will have 0 and 0 and this date should be done.

I hope that makes sense! Any help is appreciated! Thank you very much.

-- 
Yan Wu
510-333-3188 
yanni...@gmail.com

[[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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] EM algorithm for ARIMA models

2014-11-07 Thread Karim Mezhoud
EBarrays
http://www.bioconductor.org/packages/release/bioc/html/EBarrays.html

  Ô__
 c/ /'_;kmezhoud
(*) \(*)   ⴽⴰⵔⵉⵎ  ⵎⴻⵣⵀⵓⴷ
http://bioinformatics.tn/



On Fri, Nov 7, 2014 at 4:23 PM, Mathias Martens 
wrote:

> Hi there,I am working on a time series dataset with a lot of missing data
> (around60%).Specifically, I need to fit an ARIMA model to this data and I
> found thatExpectation-Maximization (EM) algorithm using Kalman filter could
> beusefull.Anyone know if already exist a package for this?Another
> approaches are usefull as well.
> Thanks,Mathias Martens
> [[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
> and provide commented, minimal, self-contained, reproducible code.
>

[[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
and provide commented, minimal, self-contained, reproducible code.


[R] EM algorithm for ARIMA models

2014-11-07 Thread Mathias Martens
Hi there,I am working on a time series dataset with a lot of missing data 
(around60%).Specifically, I need to fit an ARIMA model to this data and I found 
thatExpectation-Maximization (EM) algorithm using Kalman filter could 
beusefull.Anyone know if already exist a package for this?Another approaches 
are usefull as well.
Thanks,Mathias Martens
[[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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problem with function "polygon"

2014-11-07 Thread Eric Elguero

On 11/07/2014 04:35 PM, Duncan Murdoch wrote:


You are not using the polygon() function from the graphics package,
you're using one coming from somewhere else (maybe an old version of R,
or some package).  The polygon() function in the graphics package
doesn't call .Internal(polygon(..., it calls

.External.graphics(C_polygon, ...

If at some point you made a
copy of the polygon() function and saved it, you're stuck with that one
forever (or at least until you delete it from your workspace, or even
better, delete the whole saved workspace).



you're absolutely right. I was usin a "polygon" function
from package ade4 (that I copied to my workspace, don't
remember why). I will ask ade4 developpers.

thank you.

e.e.

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Daylight Saving Time

2014-11-07 Thread Prof Brian Ripley

On 07/11/2014 10:21, Vasantha Kumar Kesavan wrote:

I am Sorry for not explained my requirement to you properly.

As you told in Windows I need to update the $R_HOME/share/zoneinfo with the
latest time zone information, since R is not using the operating system
time zone files. Then I have updated the zoneinfo directory, after that it
is working fine for me in the windows.

In the linux platform by default R is using the operating system timezone
files available at "/usr/share/zoneinfo" path. Yesterday my question was is
it there are any way to configure the R to use different path
("/tmp/zoneinfo") instead of "/usr/share/zoneinfo".

Then from the internet I came to know that the TZDIR


Well, it is in the R help file: give credit where it is due!


(TZDIR="/tmp/zoneinfo") environment variable can be used for configure
different time zone path instead of the default path. By setting the TZDIR
environment variable in Linux does the need as I am expected. So my
requirement in Windows and Linux platform are worked out.

Now I like to know, how to do the same in Solaris operating system (when I
am tried with setting TZDIR environment variable as like Linux but no luck).


Go back to the R manuals: the recommendation for recent R on Solaris is 
to use the tzcode included in R, for which TZDIR does work.


We can write the help and manuals for you, but it is your responsibility 
to do your own homework: see the posting guide.




Thanks
Vasanth



On Fri, Nov 7, 2014 at 2:55 AM, Jeff Newmiller 
wrote:


?timezones

You probably need to recompile R.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live
Go...
   Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

On November 6, 2014 4:10:58 PM EST, Vasantha Kumar Kesavan <
info.vas...@gmail.com> wrote:

In LINUX, I don't want R to use the operating system zoneinfo(Olsen
database) instead of that I like to point different path which has the
latest zoneinfo(latest Olsen database).

On Fri, Nov 7, 2014 at 2:34 AM, Jeff Newmiller

wrote:


Working now... after what action?

AFAIK on *NIX systems R uses the OS installation of the Olsen

database, so

on a fresh login R should pick up any OS update you have installed.




---

Jeff NewmillerThe .   .  Go

Live...

DCN:Basics: ##.#.   ##.#.  Live
Go...
   Live:   OO#.. Dead: OO#..

Playing

Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.

rocks...1k





---

Sent from my phone. Please excuse my brevity.

On November 6, 2014 3:36:38 PM EST, Vasantha Kumar Kesavan <
info.vas...@gmail.com> wrote:

Thanks Jeff Newmiller, it is working now.

I would like to know, the same kind of configuration can be done in
Linux
and Solaris platform.

Instead of R is mapping to operating system(/usr/share/.
/usr/share/lib/)
zoneinfo directory.

Thanks
Vasanth

On Fri, Nov 7, 2014 at 1:18 AM, Jeff Newmiller

wrote:


R on Windows uses the Olsen timezone database, a copy of which is

stored

with R in the Program Files directory (e.g.

R/R-3.1.1/share/zoneinfo). You

could update the file yourself if you can find a corrected

version,

or

download an updated version of R.







---

Jeff NewmillerThe .   .

Go

Live...

DCN:Basics: ##.#.   ##.#.

Live

Go...
   Live:   OO#.. Dead: OO#..

Playing

Research Engineer (Solar/BatteriesO.O#.   #.O#.

with

/Software/Embedded Controllers)   .OO#.   .OO#.

rocks...1k








---

Sent from my phone. Please excuse my brevity.

On November 6, 2014 1:16:06 PM EST, Vasantha Kumar Kesavan <
info.vas...@gmail.com> wrote:

Hi,

I am working R on windows 2012 R2 platform, I have updated the

latest

hotfixes for time zone information(Microsoft KB 2981580.
).

But still R is not populating correct date time values(Standard

and

Daylight saving).

Could you please advise me, how to enable R to pick up the latest

time

zone
information/configurations.

Example:

R --vanilla
Sys.setenv(TZ = "America/Eirunepe");
dt<-c(seq(as.POSIXct("2013-11-09

20:00:00",tz="America/Eirunep

Re: [R] problem with function "polygon"

2014-11-07 Thread Duncan Murdoch

On 07/11/2014 10:05 AM, Eric Elguero wrote:

Hi all,

I'm trying to use the polygon function from
the graphics package, and get this error
message :

  > polygon(x=c(1,2,3,1),y=c(1,4,5,1))
Error in .Internal(polygon(xy$x, xy$y, col, border, lty, ...)) :
there is no .Internal function 'polygon'

That annoys me because polygon is actually
called by several other functions I need.

my R version:

R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

and I just updated everything.


You are not using the polygon() function from the graphics package, 
you're using one coming from somewhere else (maybe an old version of R, 
or some package).  The polygon() function in the graphics package 
doesn't call .Internal(polygon(..., it calls


.External.graphics(C_polygon, ...

This is one reason why it's a really bad idea to say "yes" when asked 
whether you want to save your R workspace.  If at some point you made a 
copy of the polygon() function and saved it, you're stuck with that one 
forever (or at least until you delete it from your workspace, or even 
better, delete the whole saved workspace).


Duncan Murdoch

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Lme4 Package Help!

2014-11-07 Thread Doran, Harold
Daniel

Lmer has never returned p-values from a model summary; this is a well-known and 
discussed issue. You must have post-processed the data in some way to get the 
p-values.

Our only way of helping is for you to provide sample code on what you did

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Daniel Mello
Sent: Thursday, November 06, 2014 6:24 PM
To: r-help@r-project.org
Subject: [R] Lme4 Package Help!

Hello, all! 

So, as stated in the title, the Lme4 package used to output p-values for the 
fixed effects. What happened?!

Literally 2 weeks ago, I ran code, got output with no errors, and had p-values 
listed for my fixed effects.

Now, running THE SAME CODE with THE SAME DATASET (nothing at all has changed, 
not the data, not my computer, not R, nothing), I do not get p-values.

I've tried other computers, I've tried resetting R.

Any ideas? I'd really need to get some p-values.

Thank you!

D

__
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
and provide commented, minimal, self-contained, reproducible code.

__
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
and provide commented, minimal, self-contained, reproducible code.


[R] problem with function "polygon"

2014-11-07 Thread Eric Elguero

Hi all,

I'm trying to use the polygon function from
the graphics package, and get this error
message :

> polygon(x=c(1,2,3,1),y=c(1,4,5,1))
Error in .Internal(polygon(xy$x, xy$y, col, border, lty, ...)) :
  there is no .Internal function 'polygon'

That annoys me because polygon is actually
called by several other functions I need.

my R version:

R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

and I just updated everything.

e.e.

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R version 2.14.2 installation on mac OS X Yosemite

2014-11-07 Thread peter dalgaard

On 07 Nov 2014, at 01:00 , Uwe Ligges  wrote:

> 
> 
> On 06.11.2014 20:20, Dalela, Deepansh wrote:
>> Hi,
>> 
>> I noticed your email on the R support page. I am currently using SPSS 21 for 
>> mac, and need to install a macro plug-in which requires me o install R 2.14 
>> (I already have R 3.0). When i download the R 2.14 package from the CRAN 
>> website, and try to install it on my Macintosh HD, it gives me an error 
>> message : “ R 2.14.2 for Mac OS X 10.5 or higher (Leopard build) can’t be 
>> installed on this disk. Leopard build of R requires Mac OS X 10.5 or higher. 
>> Use Tiger build (available from CRAN) for older systems.”
>> 
>> I dont understand this, since I have OS X Yosemite on my mac. I tried 
>> installing 2.14.0, but got the exact same error message.
>> 
>> Would appreciate your help greatly.
> 
> 
> 
> Such old versions of R are not supported, particularly not on more recent OS.
> If you need help, ask the company for support that tells you to install an 
> obsolete version of R.
> 
> Best,
> Uwe Ligges
> 

As Uwe says, if SPSS insists that you use outdated versions of R, SPSS should 
take on the maintenance rather than expect an academic/volunteer group to do it 
for them.  

However, Yosemite has the alphabetical-sort problem of making version 10.10 
come after 10.9 and not between 10.1 and 10.2 and I wonder if that is what is 
biting the 2.14.2 installer. There is no way that we'll be rebuilding old 
packages, but in other contexts, people have gotten around the problem by 
temporarily setting the version of Yosemite to 10.9.



>> 
>> Deepansh
>> 
>> 
>> 
>> CONFIDENTIALITY NOTICE: This email contains information from the sender that 
>> may be CONFIDENTIAL, LEGALLY PRIVILEGED, PROPRIETARY or otherwise protected 
>> from disclosure. This email is intended for use only by the person or entity 
>> to whom it is addressed. If you are not the intended recipient, any use, 
>> disclosure, copying, distribution, printing, or any action taken in reliance 
>> on the contents of this email, is strictly prohibited. If you received this 
>> email in error, please contact the sending party by reply email, delete the 
>> email from your computer system and shred any paper copies.
>> 
>> Note to Patients: There are a number of risks you should consider before 
>> using e-mail to communicate with us. See our Privacy & Security page on 
>> www.henryford.com for more detailed information as well as information 
>> concerning MyChart, our new patient portal. If you do not believe that our 
>> policy gives you the privacy and security protection you need, do not send 
>> e-mail or Internet communications to us.
>> __
>> 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
>> and provide commented, minimal, self-contained, reproducible code.
>> 
> 
> __
> 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
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
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
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Daylight Saving Time

2014-11-07 Thread Vasantha Kumar Kesavan
I am Sorry for not explained my requirement to you properly.

As you told in Windows I need to update the $R_HOME/share/zoneinfo with the
latest time zone information, since R is not using the operating system
time zone files. Then I have updated the zoneinfo directory, after that it
is working fine for me in the windows.

In the linux platform by default R is using the operating system timezone
files available at "/usr/share/zoneinfo" path. Yesterday my question was is
it there are any way to configure the R to use different path
("/tmp/zoneinfo") instead of "/usr/share/zoneinfo".

Then from the internet I came to know that the TZDIR
(TZDIR="/tmp/zoneinfo") environment variable can be used for configure
different time zone path instead of the default path. By setting the TZDIR
environment variable in Linux does the need as I am expected. So my
requirement in Windows and Linux platform are worked out.

Now I like to know, how to do the same in Solaris operating system (when I
am tried with setting TZDIR environment variable as like Linux but no luck).

Thanks
Vasanth



On Fri, Nov 7, 2014 at 2:55 AM, Jeff Newmiller 
wrote:

> ?timezones
>
> You probably need to recompile R.
> ---
> Jeff NewmillerThe .   .  Go Live...
> DCN:Basics: ##.#.   ##.#.  Live
> Go...
>   Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
> /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
> ---
> Sent from my phone. Please excuse my brevity.
>
> On November 6, 2014 4:10:58 PM EST, Vasantha Kumar Kesavan <
> info.vas...@gmail.com> wrote:
> >In LINUX, I don't want R to use the operating system zoneinfo(Olsen
> >database) instead of that I like to point different path which has the
> >latest zoneinfo(latest Olsen database).
> >
> >On Fri, Nov 7, 2014 at 2:34 AM, Jeff Newmiller
> >
> >wrote:
> >
> >> Working now... after what action?
> >>
> >> AFAIK on *NIX systems R uses the OS installation of the Olsen
> >database, so
> >> on a fresh login R should pick up any OS update you have installed.
> >>
>
> >---
> >> Jeff NewmillerThe .   .  Go
> >Live...
> >> DCN:Basics: ##.#.   ##.#.  Live
> >> Go...
> >>   Live:   OO#.. Dead: OO#..
> >Playing
> >> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
> >> /Software/Embedded Controllers)   .OO#.   .OO#.
> >rocks...1k
> >>
>
> >---
> >> Sent from my phone. Please excuse my brevity.
> >>
> >> On November 6, 2014 3:36:38 PM EST, Vasantha Kumar Kesavan <
> >> info.vas...@gmail.com> wrote:
> >> >Thanks Jeff Newmiller, it is working now.
> >> >
> >> >I would like to know, the same kind of configuration can be done in
> >> >Linux
> >> >and Solaris platform.
> >> >
> >> >Instead of R is mapping to operating system(/usr/share/.
> >> >/usr/share/lib/)
> >> >zoneinfo directory.
> >> >
> >> >Thanks
> >> >Vasanth
> >> >
> >> >On Fri, Nov 7, 2014 at 1:18 AM, Jeff Newmiller
> >> >
> >> >wrote:
> >> >
> >> >> R on Windows uses the Olsen timezone database, a copy of which is
> >> >stored
> >> >> with R in the Program Files directory (e.g.
> >> >R/R-3.1.1/share/zoneinfo). You
> >> >> could update the file yourself if you can find a corrected
> >version,
> >> >or
> >> >> download an updated version of R.
> >> >>
> >>
> >>
>
> >>---
> >> >> Jeff NewmillerThe .   .
> >Go
> >> >Live...
> >> >> DCN:Basics: ##.#.   ##.#.
> >Live
> >> >> Go...
> >> >>   Live:   OO#.. Dead: OO#..
> >> >Playing
> >> >> Research Engineer (Solar/BatteriesO.O#.   #.O#.
> >with
> >> >> /Software/Embedded Controllers)   .OO#.   .OO#.
> >> >rocks...1k
> >> >>
> >>
> >>
>
> >>---
> >> >> Sent from my phone. Please excuse my brevity.
> >> >>
> >> >> On November 6, 2014 1:16:06 PM EST, Vasantha Kumar Kesavan <
> >> >> info.vas...@gmail.com> wrote:
> >> >> >Hi,
> >> >> >
> >> >> >I am working R on windows 2012 R2 platform, I have updated the
> >> >latest
> >> >> >hotfixes for time zone information(Microsoft KB 2981580.
> >> >> >).
> >> >> >
> >> >> >But still R is not populating correct date time values(Standard
> >and
> >> >> >Daylight saving).
> >> >> >
> >> >> >Could you please advise me, how to enable R to pick up the latest
> >> >time
> >> >> >zone
> >> >> >information/co

Re: [R] To calculate the month number between 2 dates

2014-11-07 Thread Achim Zeileis

On Fri, 7 Nov 2014, Arnaud Michel wrote:


Hello
Can one calculate the month number between two dates
D1 <- "01/01/2007"  and D2 <- "01/04/2009" ?
Thank you


One way is through zoo's yearmon class:

R> library("zoo")
R> D1 <- as.yearmon("01/01/2007", format = "%d/%m/%Y")
R> D2 <- as.yearmon("01/04/2009", format = "%d/%m/%Y")
R> D2 - D1
[1] 2.25
R> 12 * (D2 - D1)
[1] 27

Other solutions could go through base R's POSIXlt class, see strptime() 
and difftime().


hth,
Z



--
Michel ARNAUD
Cirad

__
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
and provide commented, minimal, self-contained, reproducible code.



__
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
and provide commented, minimal, self-contained, reproducible code.


[R] To calculate the month number between 2 dates

2014-11-07 Thread Arnaud Michel

Hello
Can one calculate the month number between two dates
D1 <- "01/01/2007"  and D2 <- "01/04/2009" ?
Thank you


--
Michel ARNAUD
Cirad

__
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
and provide commented, minimal, self-contained, reproducible code.