[R] Plotting zoo objects with chron axis
Dear all, I have a problem which I'm not to fix. I have the following two series: a=structure(c(33242.5196150509, 34905.8434338503, 38490.6957848689, 38747.0287172129, 38919.1028597142, 39026.3956586941, 38705.5344288997, 38545.6274379387, 38651.2079354205, 38748.2769580121), index = structure(c(14029, 14032, 14033, 14034, 14035, 14036, 14039, 14040, 14041, 14042 ), class = Date), class = zoo) b=structure(c(53337.7643740991, 52210.2079727035, 50235.4480363949, 50667.1147389469, 50796.5403152116, 51113.5420947436, 51003.3603311344, 50654.0539778796, 49927.5267060329, 49320.1813921822), index = structure(c(14029, 14032, 14033, 14034, 14035, 14036, 14039, 14040, 14041, 14042 ), class = Date), class = zoo) I want to plot them on the same chart, with the x-axis the Date, and the y-axis the time in format %H:%M. At the moment, the y series is expressed in seconds from midnight. I am confused with the as.POSIXct conversion. hours(min(rollrep)) [1] 9 minutes(min(rollrep)) [1] 34 seconds(min(rollrep)) [1] 27 however, by doing the following it seems the minimum time is 11:09, which is not true. as.POSIXct(round(min(rollrep)),origin=Sys.Date()) [1] 2013-08-09 11:09:14 CEST Do you have any advice? Is there a way to plot only the hours and minutes, without having to go to the Sys.Date? Thank you, Marco -- View this message in context: http://r.789695.n4.nabble.com/Plotting-zoo-objects-with-chron-axis-tp4673412.html Sent from the R help mailing list archive at Nabble.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] Comma separated vector
Hi all, I have a vector of numbers, and to be able to pass it to RMySQL and use the IN clause I need to have this vector to be a single list numeric and comma separated. I saw the post below but it is about strings, which I do not need (I cannot pass strings in this SQL query, I need something like ' where ASSETT in (1,2,3,4,5)' http://stackoverflow.com/questions/6347356/creating-a-comma-separated-vector Any clue? -- View this message in context: http://r.789695.n4.nabble.com/Comma-separated-vector-tp4667340.html Sent from the R help mailing list archive at Nabble.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] Possible bug in 'data.table'
As somebody else replied (but for some reason did not get through it) the solution to this is to convert the variable TIME3 from POSIXlt to POSIXct. It works like a charm. Nevertheless, there is a bug in that R should give me a warning/error message, and not simply crash. I reported the bug to the relevant team. Thank you, Marco -- View this message in context: http://r.789695.n4.nabble.com/Possible-bug-in-data-table-tp4667025p4667096.html Sent from the R help mailing list archive at Nabble.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] Possible bug in 'data.table'
Dear R users, I may have found a bug in the function 'data.table'. I have a similar question as the one in this post: http://stackoverflow.com/questions/3367190/aggregate-and-weighted-mean-in-r I have a dataset with assets, quantity traded, date and time. I would like to calculate the value weighted average time of trades, by date of trade. The variables are as follows: Classes ‘data.table’ and 'data.frame': 307787 obs. of 12 variables: $ CODE: int 1 2 3 4 4 5 3 2 2 1 $ DATE : int 20070102 20070102 20070102 20070102 20070102 20070102 20070102 20070102 20070102 20070102 ... $ TIME : chr 09:14:14 09:14:33 09:26:19 09:40:45 ... $ PRICE: num 105.2 105.2 96.8 96.9 96.8 ... $ QTY : int 500 500 500 1000 500 500 1000 300 1000 500 ... $ DATE2: Date, format: 2007-01-02 2007-01-02 2007-01-02 2007-01-02 ... $ TIME2: chr 09:14:14 09:14:33 09:26:19 09:40:45 ... $ TIME3: POSIXlt, format: 2013-05-13 09:14:14 2013-05-13 09:14:33 2013-05-13 09:26:19 2013-05-13 09:40:45 ... - attr(*, .internal.selfref)=externalptr If I run the command temp[,list(weighted.mean(PRICE,QTY)),by=DATE2] I get DATE2V1 1: 2007-01-02 100.67024 2: 2007-01-03 99.89599 3: 2007-01-04 100.54347 4: 2007-01-05 100.82472 5: 2007-01-08 99.39865 --- 1524: 2012-12-19 103.73392 1525: 2012-12-20 103.77344 1526: 2012-12-21 102.89063 1527: 2012-12-27 101.53089 1528: 2012-12-28 103.35999 While I run the command temp[,list(weighted.mean(TIME3,QTY)),by=DATE2] R crashes. This behavior occurs in both R Studio and R GUI, regardless of the version (2.14, 2.15, 3.0). Is it really a bug or am I doing something wrong? -- View this message in context: http://r.789695.n4.nabble.com/Possible-bug-in-data-table-tp4667025.html Sent from the R help mailing list archive at Nabble.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] Superimpose exponential density function to histogram
Dear all, I have a large vector of durations (in seconds) and I create an histogram as follows: hist(durations,breaks=500,xlim=c(0,2000),main=,xlab=Duration (Seconds),ylab=Frequency (%),prob=TRUE) Next, I would like to superimpose the exponential distribution with the maximum likelihood estimate of lambda. To do so, I first calculate get the estimate of lambda and then try to add the curve in the following way (with error): library(MASS) lambda=fitdistr(durations,exponential)$estimate curve(rexp(1,rate=lambda),add=TRUE) Error in curve(rexp(1,rate=lambda),add=TRUE) : 'expr' must be a function, or a call or an expression containing 'x'. So I need to have an 'x', OK. But doing this does not work either: curve(dexp(durations,rate=lambda),add=TRUE) What am I doing wrong? -- View this message in context: http://r.789695.n4.nabble.com/Superimpose-exponential-density-function-to-histogram-tp4666468.html Sent from the R help mailing list archive at Nabble.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] Superimpose exponential density function to histogram
Cant believe it was that -- View this message in context: http://r.789695.n4.nabble.com/Superimpose-exponential-density-function-to-histogram-tp4666468p4666480.html Sent from the R help mailing list archive at Nabble.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] Write date class as number of days from 1970
Dear all, I have a dataset with one column being of class Date. When I write the output, I would like that column being written as number of days from 1970-01-01. I could not find anywhere a way to do it. Thanks, Marco -- View this message in context: http://r.789695.n4.nabble.com/Write-date-class-as-number-of-days-from-1970-tp4666155.html Sent from the R help mailing list archive at Nabble.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] inefficient ifelse() ?
I have a similar problem. I have a dataset and an element. If the element is equal to YY, I want to take the first column of the dataset, otherwise I want to take the second column. The following does not work, as it only evaluates the first element. Any idea? a=c(AAAXXX,BBBXXX) a=merge(a,c(AAA,BBB)) b=YY ifelse(b==YY,a,substr(a,1,3)) [1] AAAXXX -- View this message in context: http://r.789695.n4.nabble.com/inefficient-ifelse-tp3330423p4512579.html Sent from the R help mailing list archive at Nabble.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] Positioning text in top left corner of plot
Dear all, another questions related to zoo plotting. I would like to do as in the subject. Here a reproducible code: library(zoo) par(mfrow=c(2,1) plot(zoo(seq(1:10),as.Date(seq(1:10),origin=1970-01-01)),xlab=,ylab=,main=Value,las=1) mtext(EUR billions,adj=0,cex=0.7) plot(zoo(seq(1:10),as.Date(seq(1:10),origin=1970-01-01)),xlab=,ylab=,main=Value,las=1) par(xpd=T) text(par(usr)[1],par(usr)[3]+10.5,EUR billions,cex=0.7) In the first graph I use the mtext function, which does the trick but it places the text too close too the y-axis. A second possibility is to use the text function, prior specification of the option parameter par(xpd=T). However, this does not look consistent as, depending on the graph, I would need to add different numbers in the y specification of the axis (par(usr)[3]+XXX). Any idea? -- View this message in context: http://r.789695.n4.nabble.com/Positioning-text-in-top-left-corner-of-plot-tp831723p4364355.html Sent from the R help mailing list archive at Nabble.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] Positioning text in top left corner of plot
Thanks, although I still have a couple of questions: 1. What is the line parameter? I could not find it in the manual... 2. How does exactly work the adj parameter when giving two different values? -- View this message in context: http://r.789695.n4.nabble.com/Positioning-text-in-top-left-corner-of-plot-tp831723p4364757.html Sent from the R help mailing list archive at Nabble.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] Positioning text in top left corner of plot
Thanks, mtext with option 'line' does the trick. I could not see that option in my version of R, but it appeared when I installed it again. -- View this message in context: http://r.789695.n4.nabble.com/Positioning-text-in-top-left-corner-of-plot-tp831723p4365088.html Sent from the R help mailing list archive at Nabble.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] R for windows 64 bit
Dear all, I know this may have been already discussed, but I could not find a solution. I am using R 13.2 64 bit on a 64 bit machine dual core. I'm fitting a Cox proportional model to a matrix 1e06x7. Before starting the model fitting I set memory.size(max=1) and I do a clean of the garbage collector (gc()). Once launched, the program works, works, works and then, after a certain period, it reaches a standstill, with CPU usage 50% and memory usage somewhere above 5GB, flat! Maybe when swapping to the virtual memory the process gets stuck. Any idea on how to solve this issue? Best, Marco -- View this message in context: http://r.789695.n4.nabble.com/R-for-windows-64-bit-tp1011346p4288651.html Sent from the R help mailing list archive at Nabble.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] R for windows 64 bit
Dear Uwe, many thanks for your message. To reply to your questions, as you imagined I cannot provide a reproducible example. In addition, I cannot expand the memory, as I'm working on a virtual desktop. At any rate, the program is really on 'standstill' as the memory usage is flat and does not move of a single byte. I will now try with the latest R version, although I doubt it will change something. I also asked to reboot the virtual PC, to help a better memory allocation. Any other suggestion? -- View this message in context: http://r.789695.n4.nabble.com/R-for-windows-64-bit-tp1011346p4288896.html Sent from the R help mailing list archive at Nabble.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] R for windows 64 bit
It was already done, as I reduced the dataset at the minimum I could. I really need to solve this issue somehow. -- View this message in context: http://r.789695.n4.nabble.com/R-for-windows-64-bit-tp1011346p4289419.html Sent from the R help mailing list archive at Nabble.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] 45 degress line in zoo plot
Dear all, I am not able to draw a 45 degrees line in a zoo plot. The time index is a sequence of 15 min bins from 7 in the morning to 18:45 in the evening. Thanks, Marco -- View this message in context: http://r.789695.n4.nabble.com/45-degress-line-in-zoo-plot-tp3839182p3839182.html Sent from the R help mailing list archive at Nabble.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] SetInternet2, RCurl and proxy
Dear all, I am facing a problem. I am trying to install packages using a proxy, but I am not able to call the setInternet2 function, either with the small or capital s. What package do I have to call then? And, could there be a reason why this does not function? Thanks, Marco -- View this message in context: http://r.789695.n4.nabble.com/SetInternet2-RCurl-and-proxy-tp3248576p3329624.html Sent from the R help mailing list archive at Nabble.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] SetInternet2, RCurl and proxy
It says the function does not exist. The version is around 2.8, cant check right now. Is it because it's an older version? If so, is there any way to do it in a different way then? -- View this message in context: http://r.789695.n4.nabble.com/SetInternet2-RCurl-and-proxy-tp3248576p3330244.html Sent from the R help mailing list archive at Nabble.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] Plot two zoo object with different indexes
Dear R community, I have the following two zoo objects: MONTHLY CPI plot(z) par(usr) [1] 1977.76333 2011.15333 70.39856 227.03744 z=zooreg(cpius$Value,as.yearmon(1979-11),frequency=12) str(z) ‘zooreg’ series from Nov 1979 to Oct 2010 Data: num [1:372] 76.2 77 77.8 78.5 79.5 80.3 81.1 82 82 82.6 ... Index: Class 'yearmon' num [1:372] 1980 1980 1980 1980 1980 ... Frequency: 12 AND A DAILY SERIES IN THE SAME RANGE plot(y) par(usr) [1] 3233.8 15362.270.42363 226.38559 str(y) ‘zoo’ series from 1980-02-01 to 2010-10-31 Data: num [1:11231] 76.2 76.2 76.3 76.3 76.3 ... Index: Class 'Date' num [1:11231] 3683 3684 3685 3686 3687 ... Now, due to a different index (and a different usr parameter for the graphic) I am not able to plot the two series together. How shall I do? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Plot-two-zoo-object-with-different-indexes-tp3055890p3055890.html Sent from the R help mailing list archive at Nabble.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] Plot two zoo object with different indexes
Thanks as always Gabor. What I was looking for was to plot the daily series on the same graph of the monthly using the command 'lines'. That is why I wanted to change the index of one of the two, as it seems the reason why at the moment it is not working! -- View this message in context: http://r.789695.n4.nabble.com/Plot-two-zoo-object-with-different-indexes-tp3055890p3055936.html Sent from the R help mailing list archive at Nabble.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] Plot two zoo object with different indexes
Ok this helps definitely! But I still would like to know 1. How to change from one index to another within a 'zoo' object 2. How to import using as index 'Date' a monthly series (code below). The series in the US CPI from November 1979 to October 2010. z - zoo(cpius$Value, as.Date(1979-11-30)+0:372) -- View this message in context: http://r.789695.n4.nabble.com/Plot-two-zoo-object-with-different-indexes-tp3055890p3056215.html Sent from the R help mailing list archive at Nabble.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] Plot two zoo object with different indexes
Gabor Grothendieck wrote: 2. How to import using as index 'Date' a monthly series (code below). The series in the US CPI from November 1979 to October 2010. z - zoo(cpius$Value, as.Date(1979-11-30)+0:372) Assuming the question is how to turn this daily series into a monthly series: No, I have a monthly series and I want to create a zoo object indexed by date and not by class yearmon or by a number (i.e., I would like to avoid this two structures when importing monthly data and to have as index the class date) z=zooreg(cpius$Value,as.yearmon(1978-11),frequency=12) str(z) ‘zooreg’ series from Nov 1978 to Oct 2009 Data: num [1:372] 76.2 77 77.8 78.5 79.5 80.3 81.1 82 82 82.6 ... Index: Class 'yearmon' num [1:372] 1979 1979 1979 1979 1979 ... Frequency: 12 z=zooreg(cpius$Value,start=c(1978,11),frequency=12) str(z) ‘zooreg’ series from 1978.833 to 2009.75 Data: num [1:372] 76.2 77 77.8 78.5 79.5 80.3 81.1 82 82 82.6 ... Index: num [1:372] 1979 1979 1979 1979 1979 ... Frequency: 12 -- View this message in context: http://r.789695.n4.nabble.com/Plot-two-zoo-object-with-different-indexes-tp3055890p3056295.html Sent from the R help mailing list archive at Nabble.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] Plot two zoo object with different indexes
Gabor Grothendieck wrote: How to convert a monthly series to a daily series has already been illustrated in multiple ways in this thread. Fair enough. However, my last question was different. I simply want to know if there is a simple neat way to import a monthly series as a zoo object indexed by date without applying other function after the import (as in the example, using aggregate) Thanks -- View this message in context: http://r.789695.n4.nabble.com/Plot-two-zoo-object-with-different-indexes-tp3055890p3056327.html Sent from the R help mailing list archive at Nabble.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] Ordeing Zoo object
And how about if I want to order the series from the smallest to the largest value, keeping the date index in order to see when the values were predominantly negative etc... Thanks, Marco -- View this message in context: http://r.789695.n4.nabble.com/Ordeing-Zoo-object-tp955868p3054192.html Sent from the R help mailing list archive at Nabble.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] Chron object in time series plot
Ok, so you may be right, but I do not understand why ;) The commands you suggested are applied to temp_plot, where temp_plot is a 'zoo' object as follows (there is actually something strange in here, if I just want to see the whole object I do not get the warning message that I got when selecting a sample): temp_plot[1:10] 2008-01-02 2008-01-03 2008-01-04 2008-01-07 2008-01-08 2008-01-09 2008-01-10 48608 46686 55216 59268 50967 55067 57783 2008-01-11 2008-01-14 2008-01-15 60021 61480 63853 Warning message: In zoo(rval[i], x.index[i]) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique First command: temp_plot[duplicated(time(temp_plot))] Data: numeric(0) Index: character(0) Warning message: In zoo(rval[i], x.index[i]) : some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique Second command table(time(temp_plot)) , , hour = 0, mday = 23, mon = 7, year = 110, wday = 2, yday = 1, isdst = 0 min sec 0 0 0 , , hour = 0, mday = 24, mon = 7, year = 110, wday = 2, yday = 1, isdst = 0 min sec 0 0 0 , , hour = 0, mday = 25, mon = 7, year = 110, wday = 2, yday = 1, isdst = 0 min sec 0 0 0 Third command: aggregate(temp_plot,identity,length) Error: length(time(x)) == length(by[[1]]) is not TRUE Well, I believe there is something indeed going on here! If I understood correctly, the second command tells me that is not able to recognize in the correct way the year (and most likely all the rest) while the third indicates a mismatch in the dimensions. Marco -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3015182.html Sent from the R help mailing list archive at Nabble.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] Chron object in time series plot
This is the output, thanks again for the help! structure(c(48608, 46686, 55216, 59268, 50967, 55067, 57783, 60021, 61480, 63853, 58267, 72442, 63926, 49102, 74320, 63433, ... 55337, 54919, 63230, 57756, 80296, 58319, 56993, 59161, 56184, 65331, 56179, 61115, 59874, 85050), index = structure(list(sec = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, .. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), min = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, .. 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), hour = c(0L, .. 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), mday = c(2L, 3L, 4L, 7L, 8L, 9L, 10L, 11L, 14L, 15L, 16L, 17L, 18L, 21L, 22L, 23L, 24L, 25L, 28L, 29L, 30L, 31L, ... 3L, 4L, 7L, 8L, 9L, 10L, 11L, 14L, 15L, 16L, 17L, 18L, 21L, 22L, 23L, 24L, 25L, 28L, 29L, 30L, 1L, 2L, 5L, 6L, 7L, 8L, 9L, 12L, 13L, 14L, 15L, 16L, 19L, 20L, 21L, 22L, 23L, 26L, 27L, 28L, 29L, 30L), mon = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, --- 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L), year = c(108L, 108L, 108L, 108L, 108L, 108L, 108L, 108L, 108L, 108L, 108L, 108L, ...- 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L, 110L), wday = c(3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, ... 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), yday = c(1L, 2L, 3L, 6L, 7L, 8L, 9L, 10L, 13L, 14L, 15L, 16L, 17L, 20L, 21L, 22L, 23L, 24L, 27L, 28L, 29L, ... 188L, 189L, 192L, 193L, 194L, 195L, 196L, 199L, 200L, 201L, 202L, 203L, 206L, 207L, 208L, 209L, 210L), isdst = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
Re: [R] Chron object in time series plot
Here it is: dput(temp_plot) structure(c(48608, 46686, 55216, 59268, 50967, 55067, 57783, 60021, 61480, 63853, 58267, 72442, 63926, 49102, 74320, 63433, 66256, 68483, 67736, 60507, 60888, 78008, 64326, 65665, 57288, 54663, 54984, 54073, 59632, 52523, 55266, 54836, 61408, 53813, 85855, 65204, 65237, 65386, 72440, 64335, 66812, 71059, 97227, 81343, 72752, 69940, 66824, 68161, 71851, 70554, 65266, 68625, 71335, 81673, 81056, 78679, 134337, 107247, 81789, 76810, 80960, 119172, 75880, 72860, 73103, 71624, 74183, 66257, 66628, 69924, 69067, 78297, 73155, 67726, 81009, 72150, 76210, 66699, 67089, 70831, 70331, 77818, 69351, 100517, 79164, 70265, 66103, 69252, 65142, 68796, 53462, 69156, 67666, 76773, 71388, 86664, 73797, 73574, 65747, 74917, 55861, 82358, 74798, 74612, 104735, 80963, 72207, 69717, 73136, 71510, 81028, 77177, 79918, 78429, 74626, 94630, 70656, 84971, 70483, 125973, 77244, 65397, 66222, 70337, 77021, 131867, 77465, 77222, 74967, 60717, 90881, 66957, 73513, 72002, 68725, 73627, 74682, 69916, 82452, 72760, 78359, 65829, 68001, 69599, 71846, 76152, 69157, 70879, 94113, 73165, 75785, 66459, 64793, 67792, 67008, 71439, 69351, 65798, 67541, 60581, 72968, 68596, 60298, 62683, 62784, 63788, 62189, 62845, 68497, 92736, 56241, 77853, 62631, 67106, 66784, 73911, 71624, 70445, 70645, 68280, 82238, 69494, 84873, 72322, 71644, 141039, 69875, 75809, 75740, 72291, 82001, 112207, 77301, 74891, 66174, 78673, 71568, 74161, 72637, 76319, 63865, 86245, 79936, 70111, 84724, 77605, 65705, 68845, 67050, 68067, 75717, 68569, 70312, 72908, 94667, 80676, 67476, 66741, 65356, 66114, 76292, 47900, 71286, 60364, 67148, 77616, 74471, 63236, 66738, 63149, 70542, 65356, 70004, 51889, 114181, 74867, 68344, 67922, 67944, 67311, 67256, 61800, 63579, 62871, 66727, 82564, 65914, 87377, 71340, 76553, 151547, 77076, 55924, 88334, 81379, 76241, 66267, 66703, 47769, 57789, 58453, 63042, 68832, 65280, 63149, 73836, 68070, 67080, 78539, 65219, 65543, 63284, 68362, 59752, 61295, 62870, 94422, 78799, 65259, 62690, 63387, 63384, 66303, 62744, 58081, 63833, 61526, 55744, 75378, 71157, 61070, 64107, 65150, 60796, 62014, 62518, 102311, 77248, 66569, 64852, 64380, 64174, 67343, 64848, 62277, 62970, 61354, 80303, 61572, 80076, 61844, 114489, 73097, 61743, 63115, 64720, 64513, 78685, 94289, 80291, 67795, 65055, 69651, 62361, 62577, 65192, 94212, 77631, 67765, 75268, 67084, 59755, 61911, 64776, 62846, 73513, 62644, 63456, 96677, 75582, 73025, 63858, 65571, 60514, 68342, 64878, 64818, 64045, 68645, 69275, 72810, 67539, 45887, 62838, 51186, 72647, 65198, 64534, 92919, 52069, 62405, 61744, 62126, 67360, 66420, 62396, 65454, 54787, 61866, 75287, 59147, 78781, 62675, 60042, 119296, 55693, 58992, 62469, 64651, 71012, 105284, 84969, 67569, 62990, 70183, 57815, 59899, 59552, 62056, 63563, 57481, 66382, 57909, 74477, 69128, 56630, 61116, 59082, 59698, 69367, 59843, 64375, 65207, 86610, 77313, 66559, 65058, 62612, 59885, 62675, 58903, 56684, 55544, 56327, 72775, 66894, 53771, 54721, 53036, 59793, 56515, 57209, 58488, 67520, 69302, 69654, 61885, 59460, 59775, 52246, 63949, 57443, 59870, 59297, 67708, 65754, 62581, 75979, 59169, 102333, 57338, 56431, 60008, 62672, 71023, 62911, 99488, 88818, 67845, 70389, 61413, 60323, 59177, 61979, 52560, 68488, 62023, 66312, 63326, 82250, 62942, 61747, 62375, 60358, 67121, 62758, 63918, 64186, 92093, 77806, 64452, 59965, 64093, 60948, 66461, 59339, 45189, 65586, 58171, 73753, 55382, 71458, 59880, 61807, 62968, 59051, 65381, 48991, 69415, 89953, 75686, 64938, 60754, 60494, 69836, 57011, 62142, 60945, 60932, 66224, 69208, 66776, 78374, 66130, 106111, 68456, 69241, 46106, 61252, 59468, 79293, 66035, 84721, 52301, 49248, 54730, 54540, 61200, 57584, 58317, 59153, 68502, 54020, 82374, 60477, 61899, 64261, 70799, 61002, 62723, 62757, 92339, 81700, 66365, 63671, 61148, 61646, 66227, 60950, 59189, 58674, 58191, 48739, 67047, 63350, 52915, 54475, 63922, 55320, 59045, 63258, 90478, 80147, 64763, 60530, 59481, 58768, 61304, 55695, 58767, 57455, 56949, 69357, 62254, 75421, 57546, 56729, 90247, 56569, 57736, 57762, 61892, 70410, 66461, 89713, 87875, 92100, 73486, 62624, 63171, 66036, 63212, 60684, 66067, 60262, 79552, 60582, 59066, 60890, 59358, 71090, 64570, 62780, 63743, 92339, 66058, 65701, 59996, 66059, 68367, 77693, 67652, 69675, 47731, 76049, 71133, 61604, 63582, 65521, 64197, 54465, 66390, 61789, 63350, 74628, 60384, 87954, 62537, 55254, 60611, 64248, 61040, 62114, 62519, 61068, 63435, 68241, 62982, 76833, 58901, 94860, 58294, 54924, 59305, 57068, 65539, 60810, 101727, 87998, 65855, 58772, 69076, 58758, 59727, 57736, 63014, 55337, 54919, 63230, 57756, 80296, 58319, 56993, 59161, 56184, 65331, 56179, 61115, 59874, 85050), index = structure(list(sec = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Re: [R] Chron object in time series plot
Thanks for your help Gabor. That would be exactly what I am looking for. If I use your code I get the nice representation I am looking for. However, when I try to apply the code in the same fashion to my case, it does not produce the x-axis. I believe the problem hinges on the following warning message I got when creating the 'zoo' object: Warning message: In zoo(trans_numb, xtime): some methods for “zoo” objects do not work if the index entries in ‘order.by’ are not unique Actually, I do not understand why I get this warning, as my series is irregularly spaced, but does not have any duplicate (i.e. one observation per business day). -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3014100.html Sent from the R help mailing list archive at Nabble.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] Chron object in time series plot
I would like to thank you all for the help given so far! I have the following object of the class 'zoo' temp_mean_plot[31:35] 2008-02-13 2008-02-14 2008-02-15 2008-02-18 2008-02-19 14.86834 14.89609 14.89358 14.87610 14.87652 The sample runs from Jan 2008 to July 2010. How can I specify to plot for example Jan08, Jul08, Jan09 etc? I've seen some example as in example(plot.zoo) but I cant get exactly how to replicate it for my purpose. Any help will be highly appreciated again. Marco -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3012629.html Sent from the R help mailing list archive at Nabble.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] Chron object in time series plot
My bad! What I meant is that I want to plot the whole series, but the legend in the x-axis would only present some specific months depending on the window I want to choose, say 6 months. At the moment, it only present 2008, 2009 and 2010. Thanks -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3012712.html Sent from the R help mailing list archive at Nabble.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] Chron object in time series plot
I apologize for not being very precise. I meant the tick marks on the x-axis. As for the code, the situation is just the one describe above, just that I would like to be able to specify the tick marks (say every 3 or 6 months). -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3012733.html Sent from the R help mailing list archive at Nabble.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] Chron object in time series plot
Wonderful! Thanks a lot for your help, super appreciated! -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3012793.html Sent from the R help mailing list archive at Nabble.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] Chron object in time series plot
Sorry R community, I am still stucked wit this. How can avoid the x-limit error? -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3004070.html Sent from the R help mailing list archive at Nabble.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] Chron object in time series plot
Well, I was listening, but the error was due to the extra function 'format'. Without that, it works perfectly. Thanks for the help, Marco -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3004177.html Sent from the R help mailing list archive at Nabble.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] Chron object in time series plot
Dear R users, I have the following script to create bins of specified time intervals bin_end=60/bin_size bin_size=bin_size*100 h=seq(07,18,by=1) breaks=c() for (i in h) { for (j in 0:(bin_end-1)) { value=i+(bin_size)*j breaks=append(breaks,value) } } I would like to plot then using the time as x-axis. I tried the following prova=zoo(myseries,times(breaks)) but of course I got the plot with the time as 8, 9, 10 and so on. I would like only 08:00, 09:00 and so on (maybe also the half hours). How to do it? Thanks for your help, Marco -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3002285.html Sent from the R help mailing list archive at Nabble.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] Chron object in time series plot
David Winsemius wrote: You seen to be under the mistaken impression that the internal representation of DateTime classes of 08:00 would be 8. Since the internal representation of time is in seconds, the even number hours would be at integer multiples of 60*60. In addition the conversion of numeric to string in this situation may present some need to check for missing leading 0's. You ether need to describe the data situation more completely or adjust your expectations (or both). ?as.POSIXct ?strptime -- David. Thanks for the quick reply David. What I need is a simple conversion that can say 8=08:00, 94500=09:45 and 10=10:00 and so on. I agree with you that the extra leading 0s would need an extra check. The data situation is the following: I have several thousands of observations each day and I want to average them out throughout bins of a specified size (either 15 or 5 minutes). An example of the data follows, where the first column is the time and the second represents seconds between different events. example.txt 070002,1 070002,0 070002,0 070003,1 070003,0 070003,0 070003,0 070003,0 ... 100210,0 100210,0 100210,0 100210,0 100210,0 100210,0 100210,0 ... -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3002358.html Sent from the R help mailing list archive at Nabble.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] Chron object in time series plot
I do not think that importing the time as character will help me, as I need to perform several operation with them. Again, maybe I am not able to express clearly enough. Let's just focus on this series: breaks [1] 7 71500 73000 74500 8 81500 83000 84500 9 91500 93000 94500 10 101500 103000 104500 [17] 11 111500 113000 114500 12 121500 123000 124500 13 131500 133000 134500 14 141500 143000 144500 [33] 15 151500 153000 154500 16 161500 163000 164500 17 171500 173000 174500 18 181500 183000 184500 I want a simple function that can convert breaks into a treatable object by 'zoo' as follows: [1] 07:00 07:15 07:30 .. [33]... 18:00 18:15 18:30 18:45 Is this possible? -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3002458.html Sent from the R help mailing list archive at Nabble.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] Chron object in time series plot
Thanks Phil, it is exactly what I was looking for. David, I took into account how to make valid math operations, so I understand your concern about it. I will definitely change all my scripts and functions to considered the time as character, but as I need a clear output soon (deadline is close) I do not have the time now to go through all of them. But thanks again for your useful comment. There is still a remaining issue. If I do the following: test=zoo(myseries,format(strptime(sprintf('%06d',breaks),'%H%M%S'),'%H:%M')) plot(test) it does not work, as it says the following error (sorry for the Italian words) Errore in plot.window(...) : i valori 'xlim' devono essere finiti Inoltre: Warning messages: 1: In xy.coords(x, y, xlabel, ylabel, log) : si è prodotto un NA per coercizione 2: In min(x) : no non-missing arguments to min; returning Inf 3: In max(x) : no non-missing arguments to max; returning -Inf Thanks again for your help. -- View this message in context: http://r.789695.n4.nabble.com/Chron-object-in-time-series-plot-tp3002285p3002553.html Sent from the R help mailing list archive at Nabble.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] Pasting function arguments and strings
Dear R community, I am struggling a bit with a probably fairly simple task. I need to use some already existing functions as argument for a new function that I am going to create. 'dataset' is an argument, and it comprises objects named 'mean_test', 'sd_test', 'kurt_test' and so on. 'arg1' tells what object I want (mean, sd, kurt) while 'arg2' tells what to do to the object taken in 'arg1' (again could be mean, sd, but also any other operation/function). I was thinking about something like: myfunction-function(dataset,arg1,arg2) { attach(dataset) result=arg2(paste(arg1,_test)) return(result) } But this of course does not work! 'arg1' is of type closure and I cannot set it as character. Moreover, paste will create a string, and I do not think I can pass a string to the function of 'arg2'. How should I do? Thanks, Marco -- View this message in context: http://r.789695.n4.nabble.com/Pasting-function-arguments-and-strings-tp2993905p2993905.html Sent from the R help mailing list archive at Nabble.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] Pasting function arguments and strings
Thaks for your quick reply Bert, although I doubt it works. The reason is that the names of the objects of the dataset, all end with the sufix '_test' and therefore I need to attach/paste/glue this suffix to the 'arg2' of the function. Any other idea? -- View this message in context: http://r.789695.n4.nabble.com/Pasting-function-arguments-and-strings-tp2993905p2993976.html Sent from the R help mailing list archive at Nabble.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] Large dataset importing, columns merging and splitting
Dear All, I have a large data set that looks like this: CVX 20070201 9 30 51 73.25 81400 0 CVX 20070201 9 30 51 73.25 100 0 CVX 20070201 9 30 51 73.25 100 0 CVX 20070201 9 30 51 73.25 300 0 First, I would like to import it by merging column 3 4 and 5, since that is the timestamp. Then, I would like to aggregate the data by splitting them in bins of 5 minutes size, therefore from 93000 up to 93459 etc, givin as output the average price and volume in the 5 minutes bin. Hope this helps, Best, Marco -- View this message in context: http://n4.nabble.com/Large-dataset-importing-columns-merging-and-splitting-tp1294668p1294668.html Sent from the R help mailing list archive at Nabble.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] VAR forecasts and out-of-sample prediction
Dear users, I am struggling with this issue. I want to estimate a VAR(1) for three variables, say beta1 beta2 beta3, using monthly observations from January 1984 to September 2009. In-sample period January 1984 to December 2003, out-of-sample January 2004 to September 2009. This is what I have done at the moment betas-read.table(C:\\Users\\Manta\\Desktop\\betas.txt,header=T,dec=,) BETA-ts(betas,start=(1984),frequency=12) BETAS-TSdata(output=BETA) VAR1-estVARXls(window(BETAS,end=c(2003,12)),max.lag=1) pr-forecast(VAR1,horizon=1) pr3-forecast(VAR1,horizon=3) pr12-forecast(VAR1,horizon=12) and the model is estimated correctly (same estimates as found using other softwares) Then the tricky part: I want to estimate the betas for January 2004, March 2004 and January 2005 (that is, 1-3-12 months horizon). BUT, when estimating March 2004, I just want March 2004, and not also again January 2004 and February 2004. Same thing for January 2005. I tried to use the function horizonForecasts but it seems not working properly. Then, I want to compare the forecasts with the actual betas in order to get RMSE and MAE. So I tried the following: betas[241,]-pr$forecast error BETA[241,]-pr$forecast non-numeric argument to binary operator BETAS[241,]-pr$forecast incorrect number of dimensions So, I do not know how to solve this. This computation then needs to be put in a loop, with expanding (or rolling, that's not a big issue), so then I will compare betas forecasts for February 2004 (April 2004 and February 2005) with the actual data and so on. Thanks in advance! -- View this message in context: http://old.nabble.com/VAR-forecasts-and-out-of-sample-prediction-tp26540692p26540692.html Sent from the R help mailing list archive at Nabble.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] Re cursive regression
Hi there, I'm in desperate need to figure out how to solve this issue. I need to estimate a recursive model for a time series data of asset returns. The dependent variable is the asset return and then I have a set of k variables, a lagged value of the dependent variable (plus an intercept) as regressors. My sample period (monthly observations) starts on Jan 1972. What I need to do is the following: 1)use a moving window regression (window of 60 observations, i.e. 5 years) 2)estimate all the possible model (Jan 1972 Dec 1977) using a subset of the k variables (intercept and lagged values always present) and choose the best model according to thee AIC criterion 3)once the best model is chosen, make one-step ahead prediction with that model 4)go back to step 2 shifting the sample period one month ahead (i.e. Feb 1972, Jan 1978) and then repeat step 2 and 3 5)keep going until the end of the sample (May 2009) Hope it helps -- View this message in context: http://www.nabble.com/Recursive-regression-tp25682804p25682804.html Sent from the R help mailing list archive at Nabble.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] Function output
Good afternoon, I know it is a simple question but I cannot figure out how to solve this issue. I have a function that calculate two objects. I would like to choose everytime about the tree object, with default to not show it. OP-function(S=100,X,sigma,mu=0,r=0,time=1,n) { value=(S) .. tree = matrix(rev(tree), byrow = FALSE, ncol = n + 1) return(value[1]) } Thanks -- View this message in context: http://www.nabble.com/Function-output-tp25530073p25530073.html Sent from the R help mailing list archive at Nabble.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] Cross-Correlation function (CCF) issues
?? -- View this message in context: http://www.nabble.com/Cross-Correlation-function-%28CCF%29-issues-tp23145411p23156769.html Sent from the R help mailing list archive at Nabble.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] Cross-Correlation function (CCF) issues
Sorry, my bad, i did not mean to 'be mean'. Here are the first five observations for three variables (dr1, dr2 and doil) dr1 1996-01-021996-01-031996-01-041996-01-051996-01-08 0.0005814396 -0.0023725000 -0.0072835915 0.0074536448 -0.0007004221 dr2 1996-01-031996-01-041996-01-051996-01-081996-01-09 -0.0029539396 -0.0049110915 0.0147372363 -0.0081540669 -0.0003020745 do1 1996-01-02 1996-01-03 1996-01-04 1996-01-05 1996-01-08 0.08 0.01 0.17 -0.03 0.00 As you can see, dr2 is nothing but the 1st difference of dr1. In my case, I'm trying to find out the cross-correlation between the two variables do1 and dr1 up to their 10th lag (i.e. do1 with do2, do3, ..., do10,dr1,dr2,...,dr10, and the same for dr1). Hope it helps, Marco David Winsemius wrote: Are you trying to imply that people should be able to answer a question that included no data? As others have pointed out, our powers of telepathy are generally less than commonly assumed. -- View this message in context: http://www.nabble.com/Cross-Correlation-function-%28CCF%29-issues-tp23145411p23157961.html Sent from the R help mailing list archive at Nabble.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] Cross-Correlation function (CCF) issues
This is what I get. ccf(do1,dr1) Errore in na.fail.default(ts.intersect(as.ts(x), as.ts(y))) : valore mancante nell'oggetto #italian translation of 'missing values in object' ccf(do1,dr2) Errore in na.fail.default(ts.intersect(as.ts(x), as.ts(y))) : valore mancante nell'oggetto #italian translation of 'missing values in object' Could the problem be in a different version of the ccf function i have? David Winsemius wrote: When I remake those variables and try ccf(do1,dr1), the plot appears reasonable. What problem were you experiencing? It looks as though your method of differencing (whatever it was) offset the date registration of the zoo series in dr2, but ccf(do1, dr2) still does not appear to choke on that input. -- David On Apr 21, 2009, at 4:06 PM, manta wrote: DW: Modifications of that output to reconstruct the series: do1 - structure(c(0.0818, 0.008, 0.172, -0.0311, 0, 0.629, -0.317, -0.433, -0.469, -0.359), index = structure(c(9497, 9498, 9499, 9500, 9503, 9504, 9505, 9506, 9507, 9510), class = Date), class = zoo); dr1 - structure(c(0.000581439553993701, -0.00237250002417344, -0.00728359151384361, 0.00745364483017663, -0.000700422111259091, -0.00100249660582796, 0.00198943708754806, 0.000342959230417050, -0.00113732213621109, -0.00205039624417003), index = structure(c(9497, 9498, 9499, 9500, 9503, 9504, 9505, 9506, 9507, 9510), class = Date), class = zoo); dr2 - structure(c(-0.00295393957816714, -0.00491109148967017, 0.0147372363440202, -0.00815406694143572, -0.000302074494568871, 0.00299193369337603, -0.00164647785713101, -0.00148028136662814, -0.000913074107958933, -0.00247839573899256), index = structure(c(9498, 9499, 9500, 9503, 9504, 9505, 9506, 9507, 9510, 9511), class = Date), class = zoo) total number of observations is 3393 for the original data set (i.e. for do1 is 3392, for do2 is 3391 and so on) David Winsemius wrote: We still have an inadequate characterization of the data to answe the question ( as I remember it from yesterday). Missing, for example, is any information about lengths which would seem essential since (as I remember) you wantted to know why the result was so short. Why not put in a full working example with an extract of the data. Suggest you try using dput as a method of creating a working example. That way we (and the R interpreter) would get labels and class information. -- David Winsemius On Apr 21, 2009, at 10:56 AM, manta wrote: Sorry, my bad, i did not mean to 'be mean'. Here are the first five observations for three variables (dr1, dr2 and doil) dr1 1996-01-021996-01-031996-01-041996-01-051996-01-08 0.0005814396 -0.0023725000 -0.0072835915 0.0074536448 -0.0007004221 dr2 1996-01-031996-01-041996-01-051996-01-081996-01-09 -0.0029539396 -0.0049110915 0.0147372363 -0.0081540669 -0.0003020745 do1 1996-01-02 1996-01-03 1996-01-04 1996-01-05 1996-01-08 0.08 0.01 0.17 -0.03 0.00 As you can see, dr2 is nothing but the 1st difference of dr1. In my case, I'm trying to find out the cross-correlation between the two variables do1 and dr1 up to their 10th lag (i.e. do1 with do2, do3, ..., do10,dr1,dr2,...,dr10, and the same for dr1). Hope it helps, Marco In response to ?? David Winsemius wrote: Are you trying to imply that people should be able to answer a question that included no data? As others have pointed out, our powers of telepathy are generally less than commonly assumed. David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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. -- View this message in context: http://www.nabble.com/Cross-Correlation-function-%28CCF%29-issues-tp23145411p23165218.html Sent from the R help mailing list archive at Nabble.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] Cross-Correlation function (CCF) issues
The problem is that I was doing that for the tiny sample objects. So I really have no clue about David Winsemius wrote: If you were doing that with the full sized do1 and dr1, then my guess would be different data as the root cause. If you were doing this on the tiny sample objects that I created from your dput output, then I don't have an answer, since there were no missing values in those objects. -- David Winsemius On Apr 21, 2009, at 5:21 PM, manta wrote: This is what I get. ccf(do1,dr1) Errore in na.fail.default(ts.intersect(as.ts(x), as.ts(y))) : valore mancante nell'oggetto #italian translation of 'missing values in object' ccf(do1,dr2) Errore in na.fail.default(ts.intersect(as.ts(x), as.ts(y))) : valore mancante nell'oggetto #italian translation of 'missing values in object' Could the problem be in a different version of the ccf function i have? David Winsemius wrote: When I remake those variables and try ccf(do1,dr1), the plot appears reasonable. What problem were you experiencing? It looks as though your method of differencing (whatever it was) offset the date registration of the zoo series in dr2, but ccf(do1, dr2) still does not appear to choke on that input. -- David On Apr 21, 2009, at 4:06 PM, manta wrote: DW: Modifications of that output to reconstruct the series: do1 - structure(c(0.0818, 0.008, 0.172, -0.0311, 0, 0.629, -0.317, -0.433, -0.469, -0.359), index = structure(c(9497, 9498, 9499, 9500, 9503, 9504, 9505, 9506, 9507, 9510), class = Date), class = zoo); dr1 - structure(c(0.000581439553993701, -0.00237250002417344, -0.00728359151384361, 0.00745364483017663, -0.000700422111259091, -0.00100249660582796, 0.00198943708754806, 0.000342959230417050, -0.00113732213621109, -0.00205039624417003), index = structure(c(9497, 9498, 9499, 9500, 9503, 9504, 9505, 9506, 9507, 9510), class = Date), class = zoo); dr2 - structure(c(-0.00295393957816714, -0.00491109148967017, 0.0147372363440202, -0.00815406694143572, -0.000302074494568871, 0.00299193369337603, -0.00164647785713101, -0.00148028136662814, -0.000913074107958933, -0.00247839573899256), index = structure(c(9498, 9499, 9500, 9503, 9504, 9505, 9506, 9507, 9510, 9511), class = Date), class = zoo) total number of observations is 3393 for the original data set (i.e. for do1 is 3392, for do2 is 3391 and so on) David Winsemius wrote: We still have an inadequate characterization of the data to answe the question ( as I remember it from yesterday). Missing, for example, is any information about lengths which would seem essential since (as I remember) you wantted to know why the result was so short. Why not put in a full working example with an extract of the data. Suggest you try using dput as a method of creating a working example. That way we (and the R interpreter) would get labels and class information. -- David Winsemius On Apr 21, 2009, at 10:56 AM, manta wrote: Sorry, my bad, i did not mean to 'be mean'. Here are the first five observations for three variables (dr1, dr2 and doil) dr1 1996-01-021996-01-031996-01-041996-01-051996-01-08 0.0005814396 -0.0023725000 -0.0072835915 0.0074536448 -0.0007004221 dr2 1996-01-031996-01-041996-01-051996-01-081996-01-09 -0.0029539396 -0.0049110915 0.0147372363 -0.0081540669 -0.0003020745 do1 1996-01-02 1996-01-03 1996-01-04 1996-01-05 1996-01-08 0.08 0.01 0.17 -0.03 0.00 As you can see, dr2 is nothing but the 1st difference of dr1. In my case, I'm trying to find out the cross-correlation between the two variables do1 and dr1 up to their 10th lag (i.e. do1 with do2, do3, ..., do10,dr1,dr2,...,dr10, and the same for dr1). Hope it helps, Marco In response to ?? David Winsemius wrote: Are you trying to imply that people should be able to answer a question that included no data? As others have pointed out, our powers of telepathy are generally less than commonly assumed. David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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. -- View this message in context: http://www.nabble.com/Cross-Correlation-function-%28CCF%29-issues-tp23145411p23165218.html Sent from the R help mailing list archive at Nabble.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] Cross-Correlation function (CCF) issues
Here you are dput(do1[1:10]) structure(c(0.0818, 0.008, 0.172, -0.0311, 0, 0.629, -0.317, -0.433, -0.469, -0.359), index = structure(c(9497, 9498, 9499, 9500, 9503, 9504, 9505, 9506, 9507, 9510), class = Date), class = zoo) dput(dr1[1:10]) structure(c(0.000581439553993701, -0.00237250002417344, -0.00728359151384361, 0.00745364483017663, -0.000700422111259091, -0.00100249660582796, 0.00198943708754806, 0.000342959230417050, -0.00113732213621109, -0.00205039624417003), index = structure(c(9497, 9498, 9499, 9500, 9503, 9504, 9505, 9506, 9507, 9510), class = Date), class = zoo) dput(dr2[1:10]) structure(c(-0.00295393957816714, -0.00491109148967017, 0.0147372363440202, -0.00815406694143572, -0.000302074494568871, 0.00299193369337603, -0.00164647785713101, -0.00148028136662814, -0.000913074107958933, -0.00247839573899256), index = structure(c(9498, 9499, 9500, 9503, 9504, 9505, 9506, 9507, 9510, 9511), class = Date), class = zoo) total number of observations is 3393 for the original data set (i.e. for do1 is 3392, for do2 is 3391 and so on) David Winsemius wrote: We still have an inadequate characterization of the data to answe the question ( as I remember it from yesterday). Missing, for example, is any information about lengths which would seem essential since (as I remember) you wantted to know why the result was so short. Why not put in a full working example with an extract of the data. Suggest you try using dput as a method of creating a working example. That way we (and the R interpreter) would get labels and class information. -- David Winsemius On Apr 21, 2009, at 10:56 AM, manta wrote: Sorry, my bad, i did not mean to 'be mean'. Here are the first five observations for three variables (dr1, dr2 and doil) dr1 1996-01-021996-01-031996-01-041996-01-051996-01-08 0.0005814396 -0.0023725000 -0.0072835915 0.0074536448 -0.0007004221 dr2 1996-01-031996-01-041996-01-051996-01-081996-01-09 -0.0029539396 -0.0049110915 0.0147372363 -0.0081540669 -0.0003020745 do1 1996-01-02 1996-01-03 1996-01-04 1996-01-05 1996-01-08 0.08 0.01 0.17 -0.03 0.00 As you can see, dr2 is nothing but the 1st difference of dr1. In my case, I'm trying to find out the cross-correlation between the two variables do1 and dr1 up to their 10th lag (i.e. do1 with do2, do3, ..., do10,dr1,dr2,...,dr10, and the same for dr1). Hope it helps, Marco David Winsemius wrote: Are you trying to imply that people should be able to answer a question that included no data? As others have pointed out, our powers of telepathy are generally less than commonly assumed. -- View this message in context: http://www.nabble.com/Cross-Correlation-function-%28CCF%29-issues-tp23145411p23157961.html Sent from the R help mailing list archive at Nabble.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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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. -- View this message in context: http://www.nabble.com/Cross-Correlation-function-%28CCF%29-issues-tp23145411p23163878.html Sent from the R help mailing list archive at Nabble.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] Cross-Correlation function (CCF) issues
Dear all, I have two series of returns and I want to find the cross-correlations between these two series. I know of the ccf, but it does not work as I'd like if i type ccf(x,y,lag.max=20,type=correlation,plot=FALSE) i got the error message Error in na.fail.default(ts.intersect(as.ts(x), as.ts(y))) : missing values in object So i found that somebody suggested to type ccf(x,y,lag.max=20,type=correlation,na.action=na.contiguous,plot=FALSE) but in this case I can only get the cross-correlations for four lagsm whatever series i plug in the ccf functions (i.e. it's not a matter of the particular series) Any suggestions? -- View this message in context: http://www.nabble.com/Cross-Correlation-function-%28CCF%29-issues-tp23145411p23145411.html Sent from the R help mailing list archive at Nabble.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] From daily series to monthly and viceversa
Well Gabor, this is actually a really good help, thanks so much. There is only one problem, I'm getting what you say, but in the code there are a couple of errors time(z2) - as.Date(time(zz)) #probably z2 z3 - na.locf( cbind(zz, zoo(, dd), #dd object not found day.of.month = as.numeric(format(time(zz), %d)) )) z3$day.of.month - as.numeric(format(time(zz2), %d)) #z2? And why did you call partial this solution? Thanks again for you great help Take care Gabor Grothendieck wrote: Here is a partial solution: library(zoo) # z is CPI. Just use 1, 2, 3, ... for example. z - zooreg(1:12, as.yearmon(2008-01), freq = 12) days.in.month - as.numeric(as.Date(time(z), frac = 1) - as.Date(time(z)) + 1) z2 - cbind(z, z1 = lag(z, -1), z2 = lag(z, -2), z3 = lag(z, -3), days.in.month) time(z2) - as.Date(time(zz)) z3 - na.locf( cbind(zz, zoo(, dd), day.of.month = as.numeric(format(time(zz), %d)) )) z3$day.of.month - as.numeric(format(time(zz2), %d)) # now each row of z3 has all the data you need so apply(z3, 1, your.function) On Fri, Apr 17, 2009 at 2:13 PM, manta mantin...@libero.it wrote: any update anybody? I'm really stucked! -- View this message in context: http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23103052.html Sent from the R help mailing list archive at Nabble.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-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. -- View this message in context: http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23115847.html Sent from the R help mailing list archive at Nabble.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] From daily series to monthly and viceversa
Thanks so much -- View this message in context: http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23116875.html Sent from the R help mailing list archive at Nabble.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] From daily series to monthly and viceversa
any update anybody? I'm really stucked! -- View this message in context: http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23103052.html Sent from the R help mailing list archive at Nabble.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] From daily series to monthly and viceversa
Ok, I'll try to explain my issue. I have a monthly series (CPI index) and I want to interpolate it using a specific lagged harmonized formula to get the corresponding daily series. The formula is the following CPI^=CPI(t-3)+(d-1)/D*(CPI(t-2)-CPI(t-3)) where CPI^ is the CPI for the day we are calculating the reference CPI CPI(t-i) is the CPI for the month i months prior d is the day of the month for which we are calculating the reference CPI D is the number of days in the month we are calculating Then, the interpolation will give me 7 observations a week, but I need only the observations from Monday to Friday. Therefore, I will have also to discarde those estimates for Saturdays and Sundays. Hope you can help. Thanks. Marco Gabor Grothendieck wrote: You can remove missing values with: zm - aggregate(cambio, as.yearmon, mean, na.rm = TRUE) Its not clear what your second question is asking. -- View this message in context: http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23077695.html Sent from the R help mailing list archive at Nabble.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] From daily series to monthly and viceversa
I have the following daily exchange rate series (from january 1st 1996 to december 31st 2008) and I want to obtain them monthly series from it. I've read about the 'zoo' library but I'm not getting it how to do it. These are the data (left column day-month-year, right column the index) 31/12/1993 1,12509 03/01/1994 1,12509 04/01/1994 1,12558 05/01/1994 1,1258 06/01/1994 1,12596 07/01/1994 1,12753 10/01/1994 1,1273 11/01/1994 1,12416 12/01/1994 1,1275 Also, I have monthly CPI data and I want to interpolate using the reference CPI formula in order to obtain the daily series. The time window is the same (January 1996, December 2008). Thanks in advance for your help. -- View this message in context: http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23064454.html Sent from the R help mailing list archive at Nabble.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] From daily series to monthly and viceversa
Ok, thanks for the quick reply. I was not able to use the first command, but reading the quick reference helped me. Here's what I did. cambio-read.zoo(C:\\Users\\Manta\\Desktop\\useuro.txt, format = %d/%m/%Y, dec = ,,header=T) cambio #this is what i get 1996-01-01 1996-01-02 1996-01-03 1996-01-04 1996-01-05 1996-01-08 1996-01-09 1996-01-10 1996-01-11 1996-01-12 1996-01-15 1.331391.332441.327901.314061.328111.326651.32469 1.328421.329021.326801.32279 Then, using mcambio - aggregate(cambio, as.yearmon, tail, 1) mcambio gen 1996 feb 1996 mar 1996 apr 1996 mag 1996 giu 1996 lug 1996 ago 1996 set 1996 ott 1996 nov 1996 dic 1996 gen 1997 1.28836 1.30718 1.30173 1.26778 1.27209 1.27933 1.31271 1.31042 1.27980 1.28972 1.27267 1.27112 1.19681 But this is not what I wanted, because for example the january observation is not the mean of the month of january, it is simply the last observation of january. What I need is the mean of the month to be my monthly observation. Also, the series has some missing data (exchange rates are not traded every day) and every month could have different # of observation, is this going to be a problem? Thanks, Marco Gabor Grothendieck wrote: Try this: Lines - 31/12/1993 1,12509 + 03/01/1994 1,12509 + 04/01/1994 1,12558 + 05/01/1994 1,1258 + 06/01/1994 1,12596 + 07/01/1994 1,12753 + 10/01/1994 1,1273 + 11/01/1994 1,12416 + 12/01/1994 1,1275 library(zoo) z - read.zoo(textConnection(Lines), format = %d/%m/%Y, dec = ,) zm - aggregate(z, as.yearmon, tail, 1); zm Warning message: closing unused connection 3 (Lines) Dec 1993 Jan 1994 1.12509 1.12750 and read ?read.zoo, ?aggregate.zoo and the three zoo vignettes vignette(package = zoo) # lists their names vignette(zoo) # displays first one On Wed, Apr 15, 2009 at 2:26 PM, manta mantin...@libero.it wrote: I have the following daily exchange rate series (from january 1st 1996 to december 31st 2008) and I want to obtain them monthly series from it. I've read about the 'zoo' library but I'm not getting it how to do it. These are the data (left column day-month-year, right column the index) 31/12/1993 1,12509 03/01/1994 1,12509 04/01/1994 1,12558 05/01/1994 1,1258 06/01/1994 1,12596 07/01/1994 1,12753 10/01/1994 1,1273 11/01/1994 1,12416 12/01/1994 1,1275 Also, I have monthly CPI data and I want to interpolate using the reference CPI formula in order to obtain the daily series. The time window is the same (January 1996, December 2008). Thanks in advance for your help. -- View this message in context: http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23064454.html Sent from the R help mailing list archive at Nabble.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-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. -- View this message in context: http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23067288.html Sent from the R help mailing list archive at Nabble.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] From daily series to monthly and viceversa
Ok, using mcambio - aggregate(cambio, as.yearmon, mean) works perfectly!! Should I worry about the missing values or not anyway? And then I go to the following question. From monthly data to daily using a specific formula? -- View this message in context: http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23067500.html Sent from the R help mailing list archive at Nabble.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.