[R] setting up R -- VM Fusion, WIndows7

2015-07-30 Thread Matthew Johnson
Hi,

As i need R to speak to Bloomberg (and big only runs on windows), i'm
running windows 7 via VM Fusion on my mac.

I think i am having permission problems, as i cannot use install.packages,
and cannot change .libPaths via either a .Rprofile, or Profile.site.

I've posted more detail in this super-user question --
http://superuser.com/questions/948083/how-to-set-environment-variables-in-vm-fusion-windows-7

Throwing it over to this list as well, as I've spent about half the time i
had allowed for my project on (not getting) set up.

I realise this is a very niche problem - hoping that someone else has had a
similar problem, and can offer pointers.

best

mj

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] mtext bug

2012-06-02 Thread Matthew Johnson
Sir,

I have hit a the limits of my understanding of text / par / opar etc...

I have a few related xts data frames which have multiple columns, and have
written a for-loop to make a set of charts - however i do not get any
margin text when i run the loop.

when i test the code outside of the loop the margin text appears - however
when i run the loop the margin text does not appear ... what gives?

here is the code

for (col in 1:ncol(xdf)){
  par(mar=c(3.5, 4.5, 2, 1), oma=c(2,0,0,0))
  ymin = min(xdf[,col]) - 20
  ymax = max(xdf[,col]) + 20
  png(paste(drive, names(xdf)[col], '.png', sep=""))
  plot(coredata(yr09_10[,col]), type='l', ylim=c(ymin, ymax), col=1, lwd=2,
las=1, xlab="", ylab="",
   xaxt='n', main=names(xdf)[col])
  lines(coredata(yr10_11[,col]), col=2, lwd=2)
  lines(coredata(yr11_12[,col]), col=3, lwd=2)
  axis(1, at=c(1:365), labels=format(index(yr09_10), "%d-%b"), tck=0.01,
las=1)
  legend("bottom", inset=0.02, title="Financial Years", c("09/10", "10/11",
"11/12"), col=c(1,2,3), lwd=3, horiz=TRUE, bty='n')
  mtext(stamp, cex=0.75, line=0, side=1, adj=1, outer=T)
  mtext("Source: ABS", cex=0.75, side=1, adj=0, outer=T)
  dev.off()
}

the charts are certainly re-made each time (i've checked this!) and they
appear as desired, excepting the absence of the margin text.

could anyone please help?

tips on any other aspects of the above code are also very welcome.

thanks and best regards

matt johnson

[[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] mtext bug

2012-06-02 Thread Matthew Johnson
thanks very much - fixed.

On 3 June 2012 08:26, Duncan Murdoch  wrote:

> On 12-06-02 6:21 PM, Matthew Johnson wrote:
>
>> Sir,
>>
>> I have hit a the limits of my understanding of text / par / opar etc...
>>
>> I have a few related xts data frames which have multiple columns, and have
>> written a for-loop to make a set of charts - however i do not get any
>> margin text when i run the loop.
>>
>> when i test the code outside of the loop the margin text appears - however
>> when i run the loop the margin text does not appear ... what gives?
>>
>
> You're calling par() before png().  Your par() settings will apply to the
> device that was active before you open the png() device, not to it.
>
> Duncan Murdoch
>
>
>> here is the code
>>
>> for (col in 1:ncol(xdf)){
>>   par(mar=c(3.5, 4.5, 2, 1), oma=c(2,0,0,0))
>>   ymin = min(xdf[,col]) - 20
>>   ymax = max(xdf[,col]) + 20
>>   png(paste(drive, names(xdf)[col], '.png', sep=""))
>>   plot(coredata(yr09_10[,col]), type='l', ylim=c(ymin, ymax), col=1,
>> lwd=2,
>> las=1, xlab="", ylab="",
>>xaxt='n', main=names(xdf)[col])
>>   lines(coredata(yr10_11[,col]), col=2, lwd=2)
>>   lines(coredata(yr11_12[,col]), col=3, lwd=2)
>>   axis(1, at=c(1:365), labels=format(index(yr09_10), "%d-%b"), tck=0.01,
>> las=1)
>>   legend("bottom", inset=0.02, title="Financial Years", c("09/10",
>> "10/11",
>> "11/12"), col=c(1,2,3), lwd=3, horiz=TRUE, bty='n')
>>   mtext(stamp, cex=0.75, line=0, side=1, adj=1, outer=T)
>>   mtext("Source: ABS", cex=0.75, side=1, adj=0, outer=T)
>>   dev.off()
>> }
>>
>> the charts are certainly re-made each time (i've checked this!) and they
>> appear as desired, excepting the absence of the margin text.
>>
>> could anyone please help?
>>
>> tips on any other aspects of the above code are also very welcome.
>>
>> thanks and best regards
>>
>> matt johnson
>>
>>[[alternative HTML version deleted]]
>>
>> __**
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html <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.


Re: [R] mtext bug

2012-06-02 Thread Matthew Johnson
Sir,

I am now having a similar problem with the barplot: i cannot get the margin
text to 'stick'.

png(paste(drive, "MoMUnit.png", sep=""))
par(mar=c(10, 3, 2, 2), opar=(1,0,0,0))
mainnameUnit = expression(paste("MoM %", Delta, " Apptmnt Prices", sep=""))
ymin <- min(percentDiff[,c(6, 9, 33, 36, seq(15,30,3), 3)]) -1
ymax <- max(percentDiff[,c(6, 9, 33, 36, seq(15,30,3), 3)]) +1
barplot(percentDiff[,c(6, 9, 33, 36, seq(15,30,3), 3)], las=2, beside=T,
ylim=c(ymin, ymax), legend.text=c(prior2m, prior1m, ee),
main=mainnameUnit)
mtext(stamp, cex=0.75, line=0, side=1, adj=1, outer=T)
mtext("Source: ASX", cex=0.75, side=1, adj=0, outer=T)
dev.off()

i also have a few assorted issues that i cannot figure out -- i would like
to remove the box around the bar plot, and add some intro text above the
key, as i have done in the line plot case.

thanks and best regards

matt johnson

On 3 June 2012 08:38, Matthew Johnson  wrote:

> thanks very much - fixed.
>
>
> On 3 June 2012 08:26, Duncan Murdoch  wrote:
>
>> On 12-06-02 6:21 PM, Matthew Johnson wrote:
>>
>>> Sir,
>>>
>>> I have hit a the limits of my understanding of text / par / opar etc...
>>>
>>> I have a few related xts data frames which have multiple columns, and
>>> have
>>> written a for-loop to make a set of charts - however i do not get any
>>> margin text when i run the loop.
>>>
>>> when i test the code outside of the loop the margin text appears -
>>> however
>>> when i run the loop the margin text does not appear ... what gives?
>>>
>>
>> You're calling par() before png().  Your par() settings will apply to the
>> device that was active before you open the png() device, not to it.
>>
>> Duncan Murdoch
>>
>>
>>> here is the code
>>>
>>> for (col in 1:ncol(xdf)){
>>>   par(mar=c(3.5, 4.5, 2, 1), oma=c(2,0,0,0))
>>>   ymin = min(xdf[,col]) - 20
>>>   ymax = max(xdf[,col]) + 20
>>>   png(paste(drive, names(xdf)[col], '.png', sep=""))
>>>   plot(coredata(yr09_10[,col]), type='l', ylim=c(ymin, ymax), col=1,
>>> lwd=2,
>>> las=1, xlab="", ylab="",
>>>xaxt='n', main=names(xdf)[col])
>>>   lines(coredata(yr10_11[,col]), col=2, lwd=2)
>>>   lines(coredata(yr11_12[,col]), col=3, lwd=2)
>>>   axis(1, at=c(1:365), labels=format(index(yr09_10), "%d-%b"), tck=0.01,
>>> las=1)
>>>   legend("bottom", inset=0.02, title="Financial Years", c("09/10",
>>> "10/11",
>>> "11/12"), col=c(1,2,3), lwd=3, horiz=TRUE, bty='n')
>>>   mtext(stamp, cex=0.75, line=0, side=1, adj=1, outer=T)
>>>   mtext("Source: ABS", cex=0.75, side=1, adj=0, outer=T)
>>>   dev.off()
>>> }
>>>
>>> the charts are certainly re-made each time (i've checked this!) and they
>>> appear as desired, excepting the absence of the margin text.
>>>
>>> could anyone please help?
>>>
>>> tips on any other aspects of the above code are also very welcome.
>>>
>>> thanks and best regards
>>>
>>> matt johnson
>>>
>>>[[alternative HTML version deleted]]
>>>
>>> __**
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>>> PLEASE do read the posting guide http://www.R-project.org/**
>>> posting-guide.html <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] fine control of plots after use of layout(matrix ...

2012-06-03 Thread Matthew Johnson
Sir,

I would like to create a combined line-bar plot, with the line up top and
bar plot below, but with the x-axes suppressed on the topmost plot, the
line and bar plot areas joined by a common line, and the x-axes (of dates)
joined to the bottom part of the bar plot.

i have been able to format the area using the layout(matrix( ... commands,
but cannot figure out the final step.

here's the code so far:


layout(matrix(c(1,2), 2, 1, byrow=TRUE), widths=c(3,3), heights=c(2,1))
plot(saDwlPx[,1])
barplot(saDwlMoM[,1])

thanks + best regards

matt johnson

[[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] fine control of plots after use of layout(matrix ...

2012-06-03 Thread Matthew Johnson
Thanks. The solution i have been persuing is reading Murrell - and
trying to figure out grid / Viewport commands. Is it best to stay in
the base graphics package if possible?

Sent from my iPad

On 04/06/2012, at 6:20 AM, Sarah Goslee  wrote:

> On Sun, Jun 3, 2012 at 4:05 PM, Matthew Johnson  wrote:
>> Thanks. So i can call par after the layout command? I did not realise.
>
> Some par options are set by calling par() directly, while others must
> be included in the plot command itself.
>
> Sarah
>
>> Sent from my iPad
>>
>> On 03/06/2012, at 9:42 PM, Sarah Goslee  wrote:
>>
>>
>>
>> On Sunday, June 3, 2012, Matthew Johnson wrote:
>>>
>>> Sir,
>>
>>
>> I'm no sir, but you need to spend some quality time reading ?par to lean
>> abot axes and margins.
>>
>> Sarah
>>
>>>
>>> I would like to create a combined line-bar plot, with the line up top and
>>> bar plot below, but with the x-axes suppressed on the topmost plot, the
>>> line and bar plot areas joined by a common line, and the x-axes (of dates)
>>> joined to the bottom part of the bar plot.
>>>
>>> i have been able to format the area using the layout(matrix( ... commands,
>>> but cannot figure out the final step.
>>>
>>> here's the code so far:
>>>
>>>
>>> layout(matrix(c(1,2), 2, 1, byrow=TRUE), widths=c(3,3), heights=c(2,1))
>>> plot(saDwlPx[,1])
>>> barplot(saDwlMoM[,1])
>>>
>>> thanks + best regards
>>>
>>> matt johnson
>>>
>>
>> --
>> Sarah Goslee
>> http://www.stringpage.com
>> http://www.sarahgoslee.com
>> http://www.functionaldiversity.org
>
>
>
> --
> Sarah Goslee
> http://www.functionaldiversity.org

__
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] fine control of plots after use of layout(matrix ...

2012-06-03 Thread Matthew Johnson
Thank you.

Sent from my iPad

On 04/06/2012, at 7:12 AM, Sarah Goslee  wrote:

> On Sun, Jun 3, 2012 at 5:02 PM, Matthew Johnson  wrote:
>> Thanks. The solution i have been persuing is reading Murrell - and
>> trying to figure out grid / Viewport commands. Is it best to stay in
>> the base graphics package if possible?
>
> It really depends on what you need to do. Your original example used
> plot, so I went with par.
>
> Murrell's explanation of par() options is also very good.
>
> Sarah
>
>> On 04/06/2012, at 6:20 AM, Sarah Goslee  wrote:
>>
>>> On Sun, Jun 3, 2012 at 4:05 PM, Matthew Johnson  wrote:
>>>> Thanks. So i can call par after the layout command? I did not realise.
>>>
>>> Some par options are set by calling par() directly, while others must
>>> be included in the plot command itself.
>>>
>>> Sarah
>>>
>>>> Sent from my iPad
>>>>
>>>> On 03/06/2012, at 9:42 PM, Sarah Goslee  wrote:
>>>>
>>>>
>>>>
>>>> On Sunday, June 3, 2012, Matthew Johnson wrote:
>>>>>
>>>>> Sir,
>>>>
>>>>
>>>> I'm no sir, but you need to spend some quality time reading ?par to lean
>>>> abot axes and margins.
>>>>
>>>> Sarah
>>>>
>>>>>
>>>>> I would like to create a combined line-bar plot, with the line up top and
>>>>> bar plot below, but with the x-axes suppressed on the topmost plot, the
>>>>> line and bar plot areas joined by a common line, and the x-axes (of dates)
>>>>> joined to the bottom part of the bar plot.
>>>>>
>>>>> i have been able to format the area using the layout(matrix( ... commands,
>>>>> but cannot figure out the final step.
>>>>>
>>>>> here's the code so far:
>>>>>
>>>>>
>>>>> layout(matrix(c(1,2), 2, 1, byrow=TRUE), widths=c(3,3), heights=c(2,1))
>>>>> plot(saDwlPx[,1])
>>>>> barplot(saDwlMoM[,1])
>>>>>
>>>>> thanks + best regards
>>>>>
>>>>> matt johnson
>>>>>
>>>>
> --
> Sarah Goslee
> http://www.sarahgoslee.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.


[R] what does .indexDate() do - R::xts

2012-06-12 Thread Matthew Johnson
Dear R experts,

I am learning the very useful XTS package, but cannot figure out the
purpose of some commands.

in particular, the .indexDate() command does not work as expected.

say:

x <- timeBasedSeq('2010-01-01/2010-01-02 12:00')
x <- xts(1:length(x), x)

then i can subset on date as follows:

x['2010-01-01']

however the .indexDate() command does not work as expected; in
particular the following does not return anything.

x[.indexDate(x) == '2010-01-01']


I am sure i am missing something - what is .indexDate() supposed to do?


thanks and best regards


matt johnson

[[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] what does .indexDate() do - R::xts

2012-06-12 Thread Matthew Johnson
thanks. i think i understand: the difference is that the first command
converts my 'searched-for' date to a number and matches it, but the second
does not?

On 13 June 2012 12:58, Joshua Ulrich  wrote:

> On Tue, Jun 12, 2012 at 9:48 PM, Matthew Johnson 
> wrote:
> > Dear R experts,
> >
> > I am learning the very useful XTS package, but cannot figure out the
> > purpose of some commands.
> >
> > in particular, the .indexDate() command does not work as expected.
> >
> > say:
> >
> > x <- timeBasedSeq('2010-01-01/2010-01-02 12:00')
> > x <- xts(1:length(x), x)
> >
> > then i can subset on date as follows:
> >
> > x['2010-01-01']
> >
> > however the .indexDate() command does not work as expected; in
> > particular the following does not return anything.
> >
> > x[.indexDate(x) == '2010-01-01']
> >
> That's because all comparisons are FALSE.  .indexDate() returns the
> index of x, converted to the numeric representation of the Date class
> (i.e. as.Date(.indexDate(x), origin="1970-01-01") will be the Date of
> the index values).  '2010-01-01' is a character string.
>
> >
> > I am sure i am missing something - what is .indexDate() supposed to do?
> >
> Though it's not well documented, what it's doing is pretty clear from
> the source:
> R> .indexDate
> function (x)
> {
>.index(x)%/%86400L
> }
> 
>
> >
> > thanks and best regards
> >
> >
> > matt johnson
> >
>
> Best,
> --
> Joshua Ulrich  |  FOSS Trading: www.fosstrading.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.


[R] templated use of aggregate

2012-06-12 Thread Matthew Johnson
Dear R-help,

I have an xts data set that i have subset by date.

now it contains a date-time-stamp, and two columns (price and volume
traded): my objective is to create tables of volume traded at a price - and
i've been successfully using aggregate to do so in interactive use.

say the data looks as follows:

px_ym1 vol_ym1
2012-06-01 09:37:00  97.91 437
2012-06-01 09:37:00  97.91  64
2012-06-01 09:37:00  97.91   1
2012-06-01 09:37:00  97.91   5
2012-06-01 09:37:00  97.91   5
2012-06-01 09:37:00  97.92 174
2012-06-01 09:37:00  97.92  64
2012-06-01 09:37:00  97.92 125
2012-06-01 09:37:00  97.92 124
2012-06-01 09:37:00  97.92  64
2012-06-01 09:37:00  97.92 109
2012-06-01 09:37:00  97.92  64
2012-06-01 09:37:00  97.92  19
2012-06-01 09:37:00  97.92  45
2012-06-01 09:37:00  97.92  75
2012-06-01 09:37:00  97.92   3
2012-06-01 09:37:00  97.92  47
2012-06-01 09:37:00  97.91  26
2012-06-01 09:37:00  97.92   4
2012-06-01 09:37:00  97.92   1

the the following gives me what i'm looking for:

> adf <- aggregate(.~px_ym1, data=mm, sum)

which is this table:

px_ym1 vol_ym1
1  97.91 538
2  97.92 918

however now i'm trying to code it to run automatically, and use of the
templated version:

> adf <- aggregate(.~mm[,1], data=mm, sum)

yields the following - which contains what i'd like, but is has also summed
across the price column (not ideal).

  px_ym1  px_ym1 vol_ym1
1  97.91  587.46 538
2  97.92 1370.88 918

how do i code this so that i can enter an xts data-frame with arbitrary
names and still obtain the table with only the information i desire?

on a related point, is there a way to combine the two steps? the function
i've written splits by date and then returns a list containing data-frames
that report the volume traded at each price on each date

- am i re-creating the wheel here? is there canned function that does this?

thanks + best regards

matt johnson

[[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] templated use of aggregate

2012-06-13 Thread Matthew Johnson
Sorry, i'll try and put more flesh on the bones.

please note, i changed the data in the example, as fiddling has raised
another question that's best illustrated with a slightly different
data set.

first of all, when i do as you suggest, i obtain the following error:

> PxMat <- aggregate(mm[,-1] ~ mm[,1], data=mm, sum)

Error in aggregate.formula(mm[, -1] ~ mm[, 1], data = mm, sum) :
  'names' attribute [3] must be the same length as the vector [1]

my data.frame is an xts, and it looks like this:

                    px_ym1 vol_ym1
2012-06-01 09:30:00  97.90       9
2012-06-01 09:30:00  97.90      60
2012-06-01 09:30:00  97.90      71
2012-06-01 09:30:00  97.90       5
2012-06-01 09:30:00  97.90       3
2012-06-01 09:30:00  97.90      21
2012-06-01 09:31:00  97.90       5
2012-06-01 09:31:00  97.89     192
2012-06-01 09:31:00  97.89      65
2012-06-01 09:31:00  97.89      73
2012-06-01 09:31:00  97.89       1
2012-06-01 09:31:00  97.89       1
2012-06-01 09:31:00  97.89      39
2012-06-01 09:31:00  97.90      15
2012-06-01 09:31:00  97.90       1
2012-06-01 09:31:00  97.89       1
2012-06-01 09:31:00  97.90      18
2012-06-01 09:31:00  97.89       1
2012-06-01 09:32:00  97.89      33
2012-06-01 09:34:00  97.89       1
2012-06-01 09:34:00  97.89       1

dput(mn) returns:

> dput(mn)
structure(c(97.9, 97.9, 97.9, 97.9, 97.9, 97.9, 97.9, 97.89,
97.89, 97.89, 97.89, 97.89, 97.89, 97.9, 97.9, 97.89, 97.9, 97.89,
97.89, 97.89, 97.89, 9, 60, 71, 5, 3, 21, 5, 192, 65, 73, 1,
1, 39, 15, 1, 1, 18, 1, 33, 1, 1), .indexCLASS = c("POSIXct",
"POSIXt"), .indexTZ = "GMT", class = c("xts", "zoo"), index =
structure(c(1338543000,
1338543000, 1338543000, 1338543000, 1338543000, 1338543000, 1338543060,
1338543060, 1338543060, 1338543060, 1338543060, 1338543060, 1338543060,
1338543060, 1338543060, 1338543060, 1338543060, 1338543060, 1338543120,
1338543240, 1338543240), tzone = "GMT", tclass = c("POSIXct",
"POSIXt")), .Dim = c(21L, 2L), .Dimnames = list(NULL, c("px_ym1",
"vol_ym1")))

as you can see, the xts data.frame xts data.frame that contains dates,
prices and volumes. There is much more data over a long time period,
and i'm interested in various sub-setting and then aggregate
operations.

I would like to split the data by time period and aggregate the data,
such that i obtain a table which reports the volume traded at each
price, for each of the time-period splits that i have chosen.

I have employed the following approach:

PxMat <- aggregate(.~px_ym1, data=mn, sum)


which yields:

  px_ym1 vol_ym1
1  97.89     408
2  97.90     208

and for subsets, i use the following grouping:

>PxMat30 <- aggregate(.~px_ym1, data=mn[.indexmin(mn) == '30'], sum)

Which yields:

  px_ym1 vol_ym1
1   97.9     169

and

> PxMat31 <- aggregate(.~px_ym1, data=mn[.indexmin(mn) == '31'], sum)

which yields:

  px_ym1 vol_ym1
1  97.89 373
2  97.90  39

and so on and so forth for each minute.

when i try and sub-set using general notation, as follows:

PxMat <- aggregate(.~mn[,1], data=mn, sum)

this yields a different form of output:

px_ym1  px_ym1 vol_ym1
1  97.90 1076.79 408
2  97.89  979.00 208

the problem is that i now have the sum of the px_ym1 data (the sum of mn[,1])

hopefully things are now clearer - sorry to have wasted your time up
until now.

assuming that i have now made my situation clear, i am hope you can
help with four specific questions.

1/ My data-sets are HUGE, so speed is an issue - is this the fastest
way to sub-set and aggregate an xts?

2/ is there a way to do this for multiple splits? say a table for each
minute, day, week, or month? the return would potentially be a list
with a table for each day / minute etc showing volume traded at each
price -- but it doesn't have to be a list ...

i am writing a function with loops that would generate a table that
reports volume traded at each price for each case of a specified time
split (say for four tables, one for each minute in the example data,
returned as a list). my solution is slow, it seems like something that
someone would have done better already. is this the case?

3/ is there a way to do the sub-setting with templated variables? i
would like to obtain the table i get with the named aggregate
functions (reproduced above) with multiple data frames, as the column
names will differ from time to time. i cannot figure out how to stop
the command from summing the mn[,1] column when i stop using variable
names.

4/ on a related note, is it possible to apply different functions to
different columns of data? It would be nice, for example, if the table
returned from an aggregate command could be made to be:

px_ym1  count vol_ym1
1  97.90  11 408
2  97.89  10 208

where we have the price traded, the number of trades (a count of
px_ym1 / mn[,1], and the sum of vol_ym1 (mn[

Re: [R] templated use of aggregate

2012-06-13 Thread Matthew Johnson
Sorry about the cross posting - i didn't realise it was bad etiquette.

my sessioninfo was as follows:

> sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods
[7] base

other attached packages:
[1] xts_0.8-2 zoo_1.7-6

loaded via a namespace (and not attached):
[1] grid_2.14.1lattice_0.20-0


i have now updated to R 2.15, and my session info is:

> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods
[7] base

other attached packages:
[1] xts_0.8-6 zoo_1.7-7

loaded via a namespace (and not attached):
[1] grid_2.15.0lattice_0.20-6 tools_2.15.0

For the XTS object mn your suggestion still fails with an error:

> adf <- aggregate(mn[,-1]~mn[,1], data=mn, sum); adf
Error in aggregate.formula(mn[, -1] ~ mn[, 1], data = mn, sum) :
  'names' attribute [3] must be the same length as the vector [1]

however when i convert to a zoo with

> mnz <- as.zoo(mn)

I get some errors, but it works

> adf <- aggregate(mnz[,-1]~mnz[,1], data=mnz, sum); adf
Warning messages:
1: In zoo(rval, index(x)[i]) :
  some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
2: In zoo(rval, index(x)[i]) :
  some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
3: In zoo(rval[i], index(x)[i]) :
  some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
4: In zoo(rval[i], index(x)[i]) :
  some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
5: In zoo(xc[ind], ix[ind]) :
  some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
6: In zoo(xc[ind], ix[ind]) :
  some methods for “zoo” objects do not work if the index entries in
‘order.by’ are not unique
  mnz[, 1] mnz[, -1]
197.90   408
297.89   208

So is this a bug in XTS?

thanks for your patience

mj

On 13 June 2012 15:53, David Winsemius  wrote:
>
> On Jun 13, 2012, at 9:38 AM, Matthew Johnson wrote:
>
>> Sorry, i'll try and put more flesh on the bones.
>>
>> please note, i changed the data in the example, as fiddling has raised
>> another question that's best illustrated with a slightly different
>> data set.
>>
>> first of all, when i do as you suggest, i obtain the following error:
>>
>>> PxMat <- aggregate(mm[,-1] ~ mm[,1], data=mm, sum)
>>
>>
>> Error in aggregate.formula(mm[, -1] ~ mm[, 1], data = mm, sum) :
>>  'names' attribute [3] must be the same length as the vector [1]
>
>
> Very strange. When I just did it with the structure you (cross-) posted on
> SO I got:
>
>> adf <- aggregate(mm[,-1]~mm[,1], data=mm, sum); adf
> snipped warning messages
>  mm[, 1] mm[, -1]
>
> 1   97.91      538
> 2   97.92      918
>
> I had earlier tested it with a zoo object I had constructed and did it again
> with the structure below.
>
>  mm[, 1] mm[, -1]
>
> 1   97.91      538
> 2   97.92      918
>
> I'm using zoo_1.7-6 and R version 2.14.2 on a Mac. I do not remember you
> posting the requested information about your versions.
>
> --
> David.
>
>
>>
>> my data.frame is an xts, and it looks like this:
>>
>>                    px_ym1 vol_ym1
>> 2012-06-01 09:30:00  97.90       9
>> 2012-06-01 09:30:00  97.90      60
>> 2012-06-01 09:30:00  97.90      71
>> 2012-06-01 09:30:00  97.90       5
>> 2012-06-01 09:30:00  97.90       3
>> 2012-06-01 09:30:00  97.90      21
>> 2012-06-01 09:31:00  97.90       5
>> 2012-06-01 09:31:00  97.89     192
>> 2012-06-01 09:31:00  97.89      65
>> 2012-06-01 09:31:00  97.89      73
>> 2012-06-01 09:31:00  97.89       1
>> 2012-06-01 09:31:00  97.89       1
>> 2012-06-01 09:31:00  97.89      39
>> 2012-06-01 09:31:00  97.90      15
>> 2012-06-01 09:31:00  97.90       1
>> 2012-06-01 09:31:00  97.89       1
>> 2012-06-01 09:31:00  97.90      18
>> 2012-06-01 09:31:00  97.89       1
>> 2012-06-01 09:32:00  97.89      33
>> 2012-06-01 09:34:00  97.89       1
>> 2012-06-01 09:34:00  97.89       1
>>
>> dput(mn) returns:
>>
>>> dput(mn)
>>
>> structure(c(97.9, 97.9, 97.9, 97.9, 97.9, 97.9, 97.9, 97.89,
>> 97.89, 97.89, 97.89, 97.89, 97.89, 97.9, 97.9, 97.89, 97.9, 97.89,
>> 97.89, 97.89, 97.89, 9, 60, 71, 5, 3, 21, 5, 192, 6

Re: [R] templated use of aggregate

2012-06-13 Thread Matthew Johnson
thank you for your patience. i assure you i will get better with the
appropriate etiquette - and hopefully eventually contribute.

On 13 June 2012 16:18, David Winsemius  wrote:
>
> On Jun 13, 2012, at 10:09 AM, Matthew Johnson wrote:
>
>> my sessioninfo was as follows:
>>
>>> sessionInfo()
>>
>> R version 2.14.1 (2011-12-22)
>> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>>
>> locale:
>> [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods
>> [7] base
>>
>> other attached packages:
>> [1] xts_0.8-2 zoo_1.7-6
>>
>> loaded via a namespace (and not attached):
>> [1] grid_2.14.1    lattice_0.20-0
>>
>>
>> i have now updated to R 2.15, and my session info is:
>>
>>> sessionInfo()
>>
>> R version 2.15.0 (2012-03-30)
>> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>>
>> locale:
>> [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods
>> [7] base
>>
>> other attached packages:
>> [1] xts_0.8-6 zoo_1.7-7
>>
>> loaded via a namespace (and not attached):
>> [1] grid_2.15.0    lattice_0.20-6 tools_2.15.0
>>
>> For the XTS object mn your suggestion still fails with an error:
>>
>>> adf <- aggregate(mn[,-1]~mn[,1], data=mn, sum); adf
>>
>> Error in aggregate.formula(mn[, -1] ~ mn[, 1], data = mn, sum) :
>>  'names' attribute [3] must be the same length as the vector [1]
>>
>> however when i convert to a zoo with
>>
>>> mnz <- as.zoo(mn)
>>
>>
>> I get some errors, but it works
>
>
> Those are warnings, ... not errors.
>
>
>>
>>> adf <- aggregate(mnz[,-1]~mnz[,1], data=mnz, sum); adf
>>
>> Warning messages:
>> 1: In zoo(rval, index(x)[i]) :
>>  some methods for “zoo” objects do not work if the index entries in
>> ‘order.by’ are not unique
>> 2: In zoo(rval, index(x)[i]) :
>>  some methods for “zoo” objects do not work if the index entries in
>> ‘order.by’ are not unique
>> 3: In zoo(rval[i], index(x)[i]) :
>>  some methods for “zoo” objects do not work if the index entries in
>> ‘order.by’ are not unique
>> 4: In zoo(rval[i], index(x)[i]) :
>>  some methods for “zoo” objects do not work if the index entries in
>> ‘order.by’ are not unique
>> 5: In zoo(xc[ind], ix[ind]) :
>>  some methods for “zoo” objects do not work if the index entries in
>> ‘order.by’ are not unique
>> 6: In zoo(xc[ind], ix[ind]) :
>>  some methods for “zoo” objects do not work if the index entries in
>> ‘order.by’ are not unique
>>  mnz[, 1] mnz[, -1]
>> 1    97.90       408
>> 2    97.89       208
>>
>> So is this a bug in XTS?
>
>
> It does look that way to me. The correct way to report this is to contact
> the package maintainer (copied on this message) , (although I did notice
> that Joshua Ulrich already looked at this posting in SO and he is on the xts
> development team). You should have put in this at the beginning of your code
> :
>
> library(xts)
>
> --
> David.
>
>>
>> thanks for your patience
>>
>> mj
>>
>> On 13 June 2012 15:53, David Winsemius  wrote:
>>>
>>>
>>> On Jun 13, 2012, at 9:38 AM, Matthew Johnson wrote:
>>>
>>>> Sorry, i'll try and put more flesh on the bones.
>>>>
>>>> please note, i changed the data in the example, as fiddling has raised
>>>> another question that's best illustrated with a slightly different
>>>> data set.
>>>>
>>>> first of all, when i do as you suggest, i obtain the following error:
>>>>
>>>>> PxMat <- aggregate(mm[,-1] ~ mm[,1], data=mm, sum)
>>>>
>>>>
>>>>
>>>> Error in aggregate.formula(mm[, -1] ~ mm[, 1], data = mm, sum) :
>>>>  'names' attribute [3] must be the same length as the vector [1]
>>>
>>>
>>>
>>> Very strange. When I just did it with the structure you (cross-) posted
>>> on
>>> SO I got:
>>>
>>>> adf <- aggregate(mm[,-1]~mm[,1], data=mm, sum); adf
>>>
>>> snipped warning messages
>>>  mm[, 1] mm[, -1]
>>>
>>> 1   97.91      538
>>> 2   97.92      918
>>>
>>> I had earlier teste

[R] Writing data including NAs to access using RODBC

2011-12-02 Thread Matthew Johnson
Hi,

I have run into a problem writing data using RODBC. The dataframe i
have read in from access includes some NAs. I have put the data into
an xts object, manipulated the data, and would now like to append two
columns of the manipulated data to the original table in access.

I cannot append the data, nor write a new table. After some fiddling
about i think that it is that the vectors i wish to append to the
original dataframe /write include some NAs.

Is there a work around?

Thanks

Matt Johnson

__
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] Aligning time series

2012-05-14 Thread Matthew Johnson
Sir,

I have large data sets of economic indicators and would like to align
them to a reference series - say the unemployment rate or industrial
production.

Is there a canned routine that returns the optimal lead / lag
according to some (or a variety) of algorithims? not all series will
be of the same length, however i would like to constrain the matching
such that each element in the reference series matches to only one
element in the comparison series.

I do not mind if some data extend forward (in the case of series that
lead the reference series), or back (in the case of laggers or series
that are longer than the reference series).

As a toy example, say my data set is constructed as follows:

Index <- seq(0, 2*pi, length=100)

With the reference series:

S1 <- sin(index)

And the series that i want to align to S1 are:

S2 <- 2(cos(index) + runif(10)/100)
S3 <- 0.5(sin(index +pi/4) + runif(10)/100)
S4 <- sin(index + pi/3) + runif(10)/100
S4[1:25] <- NA

In this case, I am looking for a function that tells me by how many
periods i ought to advance the three series (S2, S3 and S4) to
maximise their relationship with S1 - though it is not always the case
that the reference series will lead.

Thanks and best regards

mj

__
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] Aligning time series

2012-05-14 Thread Matthew Johnson
Very useful, however as i will be aligning large datasets, is it
possible to query a variable for the lead / lag for each series? So i
can more 'automatically' align?

ideally the lag is stored in d$align or something

Best

mj

Sent from my iPad

On 14/05/2012, at 9:36 PM, Gabor Grothendieck  wrote:

> On Mon, May 14, 2012 at 5:09 AM, Matthew Johnson  wrote:
>> Sir,
>>
>> I have large data sets of economic indicators and would like to align
>> them to a reference series - say the unemployment rate or industrial
>> production.
>>
>> Is there a canned routine that returns the optimal lead / lag
>> according to some (or a variety) of algorithims? not all series will
>> be of the same length, however i would like to constrain the matching
>> such that each element in the reference series matches to only one
>> element in the comparison series.
>>
>> I do not mind if some data extend forward (in the case of series that
>> lead the reference series), or back (in the case of laggers or series
>> that are longer than the reference series).
>>
>> As a toy example, say my data set is constructed as follows:
>>
>> Index <- seq(0, 2*pi, length=100)
>>
>> With the reference series:
>>
>> S1 <- sin(index)
>>
>> And the series that i want to align to S1 are:
>>
>> S2 <- 2(cos(index) + runif(10)/100)
>> S3 <- 0.5(sin(index +pi/4) + runif(10)/100)
>> S4 <- sin(index + pi/3) + runif(10)/100
>> S4[1:25] <- NA
>>
>> In this case, I am looking for a function that tells me by how many
>> periods i ought to advance the three series (S2, S3 and S4) to
>> maximise their relationship with S1 - though it is not always the case
>> that the reference series will lead.
>
> Check out the dtw in the dtw package:
>
> library(dtw)
> d <- dtw(S1, S2)
> d$index1
> d$index2
>
> ?dtw
>
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at 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.