Re: [R] Plotting Time Series Data by Month
If you can wait a day or two, the next version (1.18) of the 'tis' package that I will put on CRAN very soon has a function called tierChart that does what you want with a 'tis' series. -- Jeff __ 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] Time series merge?
Or see mergeSeries in package 'tis'. -- Jeff __ 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-pkgs] New package list for analyzing list surveyexperiments
Well, as the author of two CRAN packages with short names (tis and fame), I maintain that short names can be fairly informative. The fame package is an interface to FAME time series databases, and the tis package implements the tis (TimeIndexedSeries) class and support classes that it needs. When writing a package, you sometimes have to make reference to its name. For example, in .C() calls I use the 'package = pkgname' argument pretty often. And it's nice to have the output from calling search() look nice. Jeff Raubertas, Richard richard_rauber...@merck.com writes: I agree that 'list' is a terrible package name, but only secondarily because it is a data type. The primary problem is that it is so generic as to be almost totally uninformative about what the package does. For some reason package writers seem to prefer maximally uninformative names for their packages. To take some examples of recently announced packages, can anyone guess what packages 'FDTH', 'rtv', or 'lavaan' do? Why the aversion to informative names along the lines of 'Freq_dist_and_histogram', 'RandomTimeVariables', and 'Latent_Variable_Analysis', respectively? -- Jeff __ 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-pkgs] New package list for analyzing list survey experiments
I know nothing about your package, but list is a terrible name for it, as list is also the name of a data type in R. -- Jeff __ 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] Documentation for library() and how to specify missing arguments
Gabor Grothendieck ggrothendi...@gmail.com writes: Try this: mx - formals(identity)$x missing(mx) [1] TRUE sin(mx) Error in sin(mx) : 'mx' is missing Neat. There's no way to look at 'mx' because calling any function with it as an argument gives that same error message, including the auto print function. What exactly is 'mx' here? -- Jeff __ 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] Subscripting a matrix-like object
jhall...@frb.gov writes: Answering my own question here, so you can ignore this unless you are really interested in some fairly obscure stuff. It turns out that this works: singleIndex - missing(j) (length(sys.call()) == length(match.call())) since sys.call() has an element for the empty argument created by x[i,] - value and match.call() does not. But it is pretty obscure. Jeff I have an S3 class called tis (Time Indexed Series) which may or may not have multiple columns. I have a function [-.tis that I've reproduced below. My question is this: inside of [-.tis, how can I distinguish between calls of the form x[i] - someValue and x[i,] - someValue ? In either case, nargs() is 3, and looking at the values from sys.call() and match.call() I could not tell them apart. Am I missing something? [-.tis - function(x, i, j, ..., value){ tif - tif(x) xStart - start(x) x - stripTis(x) if(missing(i)){ if(missing(j)) x[] - value else x[,j] - value } else { i - i[!is.na(i)] if(is.numeric(i)){ if(!is.ti(i) couldBeTi(i, tif = tif)) i - asTi(i) if(is.ti(i)){ i - i + 1 - xStart if(any(i 1)){ newRows - 1 - min(i) xStart - xStart - newRows if(is.null(m - ncol(x))) m - 1 i - i + newRows if(is.matrix(x)) x - rbind(matrix(NA, newRows, m), x) else x - c(rep(NA, newRows), x) } } } else if(!is.logical(i)) stop(non-numeric, non-logical row index) if(is.matrix(x)){ if(any(i nrow(x))){ newRows - max(i) - nrow(x) x - rbind(x, matrix(NA, newRows, ncol(x))) } if(missing(j)){ if(is.matrix(i)) x[i] - value else { if(is.logical(i)) x[i,] - rep(value, length = sum(i)*ncol(x)) else x[i,] - rep(value, length = length(i)*ncol(x)) } } else x[i,j] - value } else x[i] - value } start(x) - xStart class(x) - c(tis, oldClass(x)) x } -- Jeff __ 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] Vectorized expression to extrapolate matrix columns with columns of another matrix
Abiel X Reinhart abiel.x.reinh...@jpmchase.com writes: I have two identically sized matrices of data that represent time series (I am storing the data in zoo objects, but the idea should apply to any matrix of data). The time series in the second matrix extend further than in the first matrix, and I would like to use the data in matrix 2 to extrapolate the data in matrix 1. In other words, if mat1[i,j] == NA, then mat1[i,j] - mat1[i-1, j]*mat2[i,j]/mat2[i-1,j]. Of course, before we can calculate mat1[i,j] we may need to calculate mat1[i-1,j], and that in turn may require the computation of mat1[i-2,j], etc. This could all clearly be done with loops, but I am wondering if anyone can think of a vectorized expression or other efficient method that would work. If you use tis objects and all of the columns of mat1 become NA on the same row, i.e., mat 1 looks like this: 20100101 1 2 3 20100102 4 5 6 20100103 NA NA NA 20100104 NA NA NA then something like this should work: mat1 - naWindow(mat1) ## drops the ending NA rows rate - growth.rate(window(mat2, start = end(mat1))) growth.rate(mat1) - rate -- Jeff __ 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] Assigning Week Numbers
Take a look at the 'ti' stuff in the tis package on CRAN. If I understand you correctly, you want something like this: weekNumber - function(aDate){ aTi - ti(aDate, tif = wfriday) may1ymd - 1*year(aTi) + 501 baseWeek - ti(may1ymd, tif = wfriday) return(aTi - baseWeek + 1) } -- Jeff __ 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] aggregate for zoo or its?
Or for real power and flexibility, see the 'convert()' function in package tis. Jeff Gabor Grothendieck ggrothendi...@gmail.com writes: See ?aggregate.zoo, e.g. library(zoo) z - zoo(1:1000, as.Date(2000-01-01) + 0:999) aggregate(z, as.yearmon, mean) or replace mean with whatever summarization you want. On Sun, Mar 7, 2010 at 5:29 PM, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: The aggregate function works very well on regular time series. Is there a version for zoo or its that would take daily data and convert it to monthly, please? -- Jeff __ 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] Entire Organization Switching from SAS to R - Any experience?
Hmmm, I sense a story in the offing. Was that an accidental emergency, or one you created? Frank E Harrell Jr f.harr...@vanderbilt.edu writes: I differ with Marc in one way. It is amazing what people can learn when you create an emergency for them to do so. Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University -- Jeff __ 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] dividing ts objects of different frequencies
Stephen J. Barr stephenjb...@gmail.com writes: I have two time series (ts) objects, 1 is yearly (population) and the other is quarterly (bankruptcy statistics). I would like to produce a quarterly time series object that consists of bankruptcy/population. Is there a pre-built function to intelligently divide these time series: What you need to do is create a quarterly population series, then divide it into your bankruptcy series. The only nice way I know to do this is to use the convert() function from my tis package. Here is it's help document: convert package:tis R Documentation Time scale conversions for time series Description: Convert 'tis' series from one frequency to another using a variety of algorithms. Usage: convert(x, tif, method = constant, observed. = observed(x), basis. = basis(x), ignore = F) Arguments: x: a univariate or multivariate 'tis' series. Missing values (NAs) are ignored. tif: a number or a string indicating the desired ti frequency of the return series. See 'help(ti))' for details. method: method by which the conversion is done: one of discrete, constant, linear, or cubic. Note that this argument is effectively ignored if 'observed.' is high or low, as the discrete method is the only one supported for that setting. observed.: observed attribute of the input series: one of beginning, end, high, low, summed, annualized, or averaged. If this argument is not supplied and observed('x') != NULL it will be used. The output series will also have this observed attribute. basis.: daily or business. If this argument is not supplied and basis('x') != NULL it will be used. The output series will also have this basis attribute. ignore: governs how missing (partial period) values at the beginning and/or end of the series are handled. For method == discrete or constant and ignore == T, input values that cover only part the first and/or last output time intervals will still result in output values for those intervals. This can be problematic, especially for observed == summed, as it can lead to atypical values for the first and/or last periods of the output series. Details: This function is a close imitation of the way FAME handles time scale conversions. See the chapter on Time Scale Conversion in the Users Guide to Fame if the explanation given here is not detailed enough. Start with some definitions. Combining values of a higher frequency input series to create a lower frequency output series is known as 'aggregation'. Doing the opposite is known as 'disaggregation'. If observed == high or low, the discrete method is always used. Disaggration for discrete series: (i) for observed == beginning (end), the first (last) output period that begins (ends) in a particular input period is assigned the value of that input period. All other output periods that begin (end) in that input period are NA. (ii) for observed == high, low, summed or averaged, all output periods that end in a particular input period are assigned the same value. For summed, that value is the input period value divided by the number of output periods that end in the input period, while for high, low and averaged series, the output period values are the same as the corresponding input period values. Aggregation for discrete series: (i) for observed == beginning (end), the output period is assigned the value of the first (last) input period that begins (ends) in the output period. (ii) for observed == high (low), the output period is assigned the value of the maximum (minimum) of all the input values for periods that end in the output period. (iii) for observed == summed (averaged), the output value is the sum (average) of all the input values for periods that end in the output period. Methods constant, linear, and cubic all work by constructing a continuous function F(t) and then reading off the appropriate point-in-time values if observed == beginning or end, or by integrating F(t) over the output intervals when observed == summed, or by integrating F(t) over the output intervals and dividing by the lengths of those intervals when observed == averaged. The unit of time itself is given by the 'basis' argument. The form of F(t) is determined by the conversion method. For constant conversions, F(t) is a step function with jumps at the boundaries of the input periods. If the first and/or last input periods only partly cover an output period, F is linearly extended to cover the first and last output periods as
Re: [R] windows vs. linux code
Rolf Turner r.tur...@auckland.ac.nz writes: Despite the knowledge, wisdom, insight, skill, good looks, and other admirable characteristics of the members of the R-help list, few of us are skilled in telepathy or clairvoyance. Oh, yeah? Then how did I know you were going to say that, huh? -- Jeff __ 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 scripts and parameters
Here's how I do this: The last lines of my .First() function are these: ## Run command line program if there is one if(length(.cmd - commandArgs(trailingOnly = TRUE)) 0) try(source(textConnection(.cmd), echo = T, prompt.echo = )) and on my Linux path I have this csh script, called runR #! /bin/csh # This is the runR script. # It starts R in a specified directory (default /mra/prod/R) # and submits the string given as its last argument to that R process. # To submit multiple Rcommands, use a single string with the commands # separated by semi-colons. # set usage = 'runR [-d directory] cmd1; cmd2; cmd3' # # Example: runR chartControl() # #starts R and immediately invokes the chartControl() #function, and exits when chartControl() does. if ($#argv == 0 ) then echo $usage exit(1) endif set rDir = /mra/prod/R if($1 == -d) then shift set directory = $1 shift else set directory = $rDir endif umask 002 cd $directory set log = $rDir/tmp/runR.log if( -e $log ) then set nLines = `wc -l $log | awk '{print $1}'` if($nLines 25000) then tail -2 $log $log.tmp mv $log.tmp $log endif endif R --no-save --args $argv ; q() | tee -a $log # end of runR script -- Jeff __ 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] how to study the lead and lag relation of two time series?
Yes, it's called Ocular Econometrics. You plot both series on the same chart and use your onboard pattern detector. If you can't see it on the plot, it's unlikely that any correlations you find in other ways will have much predictive power, and that's the only kind of relationship that counts. I know you asked for a systematic way to do this, but at least with economic time series, experience tells me that correlations that can't be seen with the naked eye are rarely meaningful. I'm now ready to duck all the brickbats that are about to come my way. Jeff Michael comtech@gmail.com writes: Hi all, Is there a way to study the lead and lag relation of two time series? Let's say I have two time series, At and Bt. Is there a systematic way of concluding whether it's A leading B or B leading A and by how much? Thanks! -- Jeff __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with FAME
My bad. I used system(test -r blah) to see if a file was readable, forgetting that not all Windows installations have the test program (from Cygwin) installed. I've changed this to use the R function file.access() in version 2.5, which I've just submitted to CRAN. The Windows binary should be available from there in a day or two. Jeff Boriss bor...@gmx.net writes: Dear All, I wonder whether anyone has an experience with FAME package written by Jeff Hallman. All my attempts to send him the following problem report did not succeed (the mail system says that my e-mail could not be delivered), so I turn for help to this list. I tried to use your FAME package written for R, but somehow I cannot get it working. I am using Windows XP and the newest R installation version 2.8.1. For example, if I run the following code I get the following error message: library(fame) mydb - O:/FameDB/national.db mydb fameWhats(mydb,TS21555100,getDoc = T) getfame(TS21555100,mydb) library(fame) mydb - O:/FameDB/national.db mydb [1] O:/FameDB/national.db fameWhats(mydb,TS21555100,getDoc = T) Fehler in fameWhats(mydb, TS21555100, getDoc = T) : cannot read O:/FameDB/national.db Zusätzlich: Warning message: In system(paste(test -r, path), intern = F) : test nicht gefunden getfame(TS21555100,mydb) Fehler in getfame(TS21555100, mydb) : cannot read O:/FameDB/national.db Zusätzlich: Warning message: In system(paste(test -r, path), intern = F) : test nicht gefunden --- I have a German installation and the phrase „test nicht gefunden“ means “the test has not been found”. We have a running version of FAME at our institute and from within FAME I can download this variable without problem: $open national whats TS21555100 produces: Offene Datenbanken: NATIONAL TS21555100 KOF: Vollzeitaequivalente Beschaeftigung (in 1000 Pers.) Class: SERIES DB name: NATIONAL Type: NUMERIC Created: 27-Nov-08 Index: DATE:QUARTERLY Updated: 27-Nov-08 First Value at: 75:3 Observed: SUMMED Last Value at: 08:3 Basis:DAILY OVERLAY(TS21560100, TS21555100) „Vollzeitaequivalente Beschaeftigung“ stands for „Full-time equivalent employment“ Also, I have the same error message when I run the code from the manual: seriesA - tis(1:24,start=c(2002,1),freq =12) seriesB - tis(1:104, start = c(2002, 1), tif = wmonday) documentation(seriesB) - paste(Line, 1:4, of seriesB documentation) putfame(c(mser = seriesA, wser = seriesB), db = myfame.db) Warning message: In system(paste(test -r, path), intern = F) : test nicht gefunden In the CRAN webpage I read that „ The fame package can access Fame time series databases (but also requires a Fame backend). The tis package provides time indices and time-indexed series compatible with Fame frequencies. ” However, I don’t understand what “a Fame backend” means and how it can be useful for running your package? Thank you for your help. Best wishes, Boriss Siliverstovs -- __ 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. -- Jeff __ 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 in the NY Times
The article quotes John Chambers, but it doesn't mention that R started out as an implementation of the S language. I don't suppose Insightful is too happy about that. The SAS spokesman quoted in the article is clearly whistling past the graveyard. -- Jeff __ 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] question about the tisPlot function in package tis
[EMAIL PROTECTED] writes: List, I am using the 'tisPlot' function in Jeff Hallman's excellent tis package and was hoping that someone could spare me from having to dig into the code of his 'tisPlot' function. So far as I can tell, the preferred method of controlling the plotting of the x-axis is using the 'xTickFreq' and 'xTickSkip' options. Unfortunately, the where the data ends up on the resultant plot is not invariant to this choice, as indicated in the documentation of the 'xTickFreq' option. Has anyone adjusted the frequency of their x-axis label using this package before? I imagine that there must be a better way of doing what I am trying to accomplish, but if not, does anyone have a suggestion on how to work around this without digging into the function itself? ## an example library(tis) strt - ti(2101, monthly) dat - tis(runif(9*12 - 1), start=strt) # ends in 11/2008 par(mfrow=c(2,1)) tisPlot(dat, xTickFreq=monthly, xTickSkip=6) # graph ends in 11/2008, but looks to start some time in late 1999 tisPlot(dat, xTickFreq=monthly, xTickSkip=12) # graph looks to end around 3/2009 Try this: tisPlot(dat, xTickFreq = annual, xMinorTickFreq = monthly) I don't understand what you mean by where the data ends up on the resultant plot is not invariant to this choice, as indicated in the documentation of the 'xTickFreq' option. The documentation for xTickFreq says: xTickFreq: a string like the ones returned by 'tifName'. This argument and 'xTickSkip' jointly specify locations for labeled x axis ticks as follow: (i) find the 'ti''s of the given frequency that correspond to 'xAxisMin' and 'xAxisMax', then (ii) including those as endpoints, generate a sequence of every 'xTickSkip''th 'ti' between them. Two special strings can also be given. none means no labelled tick marks, while auto tries (not always successfully) to come up with reasonable tick locations automatically. auto also overrides any 'xTickSkip' setting. The default is auto. which does not indicate that your data points are moved. At any rate, please try my suggestion above, which gives a pretty nice axis for your time range. Jeff __ 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] Cannot quit R - fame package issue?
I am the author of the 'fame' package, and I can confirm that earlier versions did indeed use Greg Warnes addLast() function to add to the user's .Last() function. The current version no longer does so. Jeff Dan Slayback [EMAIL PROTECTED] writes: Thanks very much for the tips. Simply removing .Last did allow me to exit, and looking at sessionInfo showed that there was a fame_2.3 namespace loaded, even without loading the fame package, which I guess had this remnant code for .Last from a previous version of fame (there appears to be no .Last in the current version of fame): sessionInfo() R version 2.8.0 (2008-10-20) x86_64-redhat-linux-gnu locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] fame_2.3 loadedNamespaces() [1] base fame graphics grDevices methods stats [7] utils So after unloading the namespace fame, and rm(.Last), and re-saving the workspace, I can now exit without problems - thanks! Prof Brian Ripley wrote: See the help for .Last: Immediately _before_ terminating, the function '.Last()' is executed if it exists and 'runLast' is true. If in interactive use there are errors in the '.Last' function, control will be returned to the command prompt, so do test the function thoroughly. You can avoid it via arguments to q() (see its help). However, if the 'fame' package has been ill-mannered enough to put a .Last in your workspace, then you can and should delete it and re-save the workspace. I can't see the function validServerIsRunning in the current fame package, so it may be a legacy of a workspace from an earlier version. Packages really should not be using the user's workspace, and in particular not setting .Last there. A couple of packages do have .Last in their space, but it is not guaranteed that their version will be visible: reg.finalizer() is the way to do this in a package. On Mon, 17 Nov 2008, Dan Slayback wrote: Hello list member: I've recently had a problem in that I'm unable to quit an R Session. I noticed this after the update to 2.8.0, but I believe I also noticed it on another machine, in the previous version. It occurs on both linux and Mac platforms. It only occurs when I start R in some particular workspaces that have alot of objects in them; it does not occur if I start R in an empty workspace. I dont have to do anything in the workspace after starting R to get this to occur, and no packages are loaded by default. Here's a summary from a Linux environment: -- $ R R version 2.8.0 (2008-10-20) Copyright (C) 2008 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. [Previously saved workspace restored] search() [1] .GlobalEnvpackage:stats package:graphics [4] package:grDevices package:utils package:datasets [7] package:methods Autoloads package:base q() Save workspace image? [y/n/c]: n Error in .Last() : could not find function validServerIsRunning .Last function () { if (exists(fameRunning) fameRunning()) fameStop() if (validServerIsRunning()) endServerSession() } environment: namespace:fame -- As the .Last function is referring to the fame package, I figure it must be something to do with that. There are objects in the workspace that require fame to be loaded, but at this point, I have not loaded the fame package, or accessed those objects. If loaded, the same error occurs when trying to quit. Thanks in advance for any suggestions on how to troubleshoot this. Dan __ 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. -- ___ Dan Slayback, PhD Research Scientist Science Systems and Applications, Inc. tel: (301) 614-6687 Biospheric Sciences Branch, Code
Re: [R] Truncating dates (and other date-time manipulations)
hadley wickham [EMAIL PROTECTED] writes: dates - structure(c(8516, 8544, 8568, 8596, 8609, 8666, 8701, 8750, 8754, 8798, 8811, 8817, 8860, 8873, 8918, 8931, 8966, 9020, 9034, 9056 ), class = Date) range(dates) [1] 1993-04-26 1994-10-18 as.Date(ti(range(dates), monthly)) [1] 1993-04-30 1994-10-31 as.Date(ti(range(dates), annual)) [1] 1993-12-31 1994-12-31 What's the easiest way to control whether the dates are rounded up or down? dates [1] 1993-04-26 1993-05-24 1993-06-17 1993-07-15 1993-07-28 [6] 1993-09-23 1993-10-28 1993-12-16 1993-12-20 1994-02-02 [11] 1994-02-15 1994-02-21 1994-04-05 1994-04-18 1994-06-02 [16] 1994-06-15 1994-07-20 1994-09-12 1994-09-26 1994-10-18 A ti represents a period, not a date. So ti(dates, monthly) [1] 19930430 19930531 19930630 19930731 19930731 19930930 19931031 19931231 [9] 19931231 19940228 19940228 19940228 19940430 19940430 19940630 19940630 [17] 19940731 19940930 19940930 19941031 class: ti is giving you ti's for the months. The print method for ti shows the last mmdd date for the period, but the ti's actually represent the months, not their last days. You can see this if you do this: format(ti(dates, monthly), %b %Y) [1] Apr 1993 May 1993 Jun 1993 Jul 1993 Jul 1993 Sep 1993 [7] Oct 1993 Dec 1993 Dec 1993 Feb 1994 Feb 1994 Feb 1994 [13] Apr 1994 Apr 1994 Jun 1994 Jun 1994 Jul 1994 Sep 1994 [19] Sep 1994 Oct 1994 When you convert the months to Dates with as.Date(), then you get the dates for the ends of the months. If you want ti's for the months just before the months your dates fell into, just subtract 1., i.e., ti(dates, monthly) - 1 [1] 19930331 19930430 19930531 19930630 19930630 19930831 19930930 19931130 [9] 19931130 19940131 19940131 19940131 19940331 19940331 19940531 19940531 [17] 19940630 19940831 19940831 19940930 class: ti And to get the starting period I just subtract one from the ti object and then add one to the Date object? That will work, or you can do firstDayOf(ti(dates, monthly)) to get a vector with daily ti's for the first days of the months that 'dates' fell into, and you can use as.Date() on that, if you want to convert them to a Date object. Is there any standard way to do multiples of periods? (e.g. 3 weeks, 4 days). If you want this week and every third week after that, you can do this: seq(ti(today(), wsaturday), by = 3, len = 4) [1] 20080913 20081004 20081025 20081115 class: ti which is equivalent to; ti(today(), wsaturday) + 3*(0:3) [1] 20080913 20081004 20081025 20081115 class: ti And is the finest resolution of a ti object a day? I don't think I see any periods less than that in the output of tif() The output of tif() does not show all the hourly, minutely, and secondly frequencies because there are so many possibilities. Here is the help page that ? hourly shows you: - R support for FAME-style Intraday frequencies Description: create 'tif' (TimeIndexFrequency) codes for hourly, minutely, and secondly 'ti''s. Usage: hourly(n = 0) minutely(n = 0) secondly(n = 0) Arguments: n: number of base periods to skip. That is, 'hourly(2)' gives a 'tif' code for a series observed every 2nd hour, while both 'minutely()' and 'minutely(1)' are for a series observed once per minute, 'secondly(30)' means every 30 seconds, and so on. Details: The current implementation has hourly(n) - 2000 + n, minutely(n) - 3000 + n, and secondly(n) - 4000 + n. If 'n' divides evenly into 3600 for 'secondly(n)', the return code will be the same as 'hourly(n/3600)'. For 'secondly(n)' and 'minutely(n)', if 'n' divides evenly into 60, the return code will be as if 'minutely(n/60)' or 'hourly(n/60)' had been called, respectively. For 'hourly(n)', 'n' must evenly divide into 24 and be less than 24, i.e., 'n' is one of 1, 2, 3, 4, 6, 8, 12. For 'minutely(n)', 'n' must be an even divisor of 1440, and less than 720. For 'secondly(n)', 'n' must divide evenly into 86400, and be no larger than 960. Value: An integer 'tif' code. - So to create a ti object for every quarter-hour starting right now, I could do: seq(ti(Sys.time(), minutely(15)), by = 1, len = 12) [1] 20080912:09:30:00 20080912:09:45:00 20080912:10:00:00 20080912:10:15:00 [5] 20080912:10:30:00 20080912:10:45:00 20080912:11:00:00 20080912:11:15:00 [9] 20080912:11:30:00 20080912:11:45:00 20080912:12:00:00 20080912:12:15:00 class: ti and if I wanted one every 45 minutes, I could do this: seq(ti(Sys.time(), minutely(15)), by = 3, len = 12) [1] 20080912:09:30:00 20080912:10:15:00 20080912:11:00:00 20080912:11:45:00 [5] 20080912:12:30:00 20080912:13:15:00 20080912:14:00:00 20080912:14:45:00 [9] 20080912:15:30:00 20080912:16:15:00 20080912:17:00:00 20080912:17:45:00
Re: [R] Truncating dates (and other date-time manipulations)
Look at the ti (Time Index) class in package tis. Here's some examples I just did: x - Sys.Date() x [1] 2008-09-11 ti(x, wsaturday) ## a ti for the week that x falls into [1] 20080913 class: ti ti(x + 1, wsaturday) - 1 ## ti for the latest complete week [1] 20080906 class: ti as.Date(ti(x + 1, wsaturday) - 1) ## as a Date [1] 2008-09-06 ymd(ti(x + 1, wsaturday) - 1) ## or just the mmdd number [1] 20080906 You can do the same for wsunday, if you want weeks that end on Sunday. In all, ti supports 7 different weekly frequencies, for weeks ending on Monday, Tuesday, ..., Sunday. It also has daily and business day frequencies, 14 biweekly frequencies, semimonthly, monthly, bimonthly, and three quarterly frequencies (for quarters that end in October, November and December). Similarly, there are 12 annual frequencies and 6 semiannual ones, and a biannual frequency. Also supported are hourly, minutely and secondly frequencies. Gabor and I have done some work towards making zoo and ti objects compatible with each other. hadley wickham [EMAIL PROTECTED] writes: I've been struggling to perform common operations on dates that I need to be able to correct draw date-time scales - in particular I need to be able to round/truncate/ceiling dates to arbitrary precision - e.g. to weeks, months or years (or multiples thereof). I haven't been able to find anything to do this in base R (trunc.Date only truncates to sub-day units), or in the date related contributed packages I've looked in (e.g. chron). Have I missed something? -- Jeff __ 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] time series by calendar week
Or look at the fame package, which has ti (TimeIndex) and tis (TimeIndexedSeries) classes that handle this kind of problem. I think it's simpler and faster than the zoo stuff, but then I would say that, since I wrote it. Jeff stephen sefick [EMAIL PROTECTED] writes: I don't know if this will help, but look at the zoo, chron, and Posix Date Time packages/classes. On Tue, Jul 8, 2008 at 10:25 AM, collonil [EMAIL PROTECTED] wrote: hello, i cant find a solution on this (might be) easy problem: i have a time serie by carlandar weeks, so for every carlendar week i have a value. now i would like to use the functions for time series, so i change structur to a time serie with cam - ts(number,start=c(2001,1),deltat=7/365) or cam - ts(number,start=c(2001,1),frequency=52) the problem on it is, that 2004 had 53 calendar weeks, which is not recognized there. it follows with using a saisonal structure the weeks are shifting. f.e. first week in 2005 is conected with the second week in 2004. with the first function leap years are not recognized. is there another function which is recognizing irregularities in the calendar? thanks a lot, collonil -- View this message in context: http://www.nabble.com/time-series-by-calendar-week-tp18340479p18340479.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. -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[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. -- Jeff __ 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] help with oop in R - class structure and syntex
tom soyer [EMAIL PROTECTED] writes: (1) how do I encapsulate the generics? i.e., if a class has 100 methods, then does it mean 100 generics would be dumped in the global environment? Or, is it possible to define a local environment and restrict the generics from one class to a particular environment? But then how do you call the generics from a special environment? Also, is it possible to inherit classes across different environment? I think the answer is: you can't. There is no sensible way to assign multi-methods to a particular class. So you have to have some sort of database of methods and signatures that gets consulted by the dispatcher. How you do a sensible IDE with this setup is beyond me. This is my biggest gripe with S4 methods: there doesn't seem to be any good way to browse the environment and discover whats already in there. S3 methods are much easier to follow. You can do multiple dispatch with S3 methods, but hardly anyone ever does. My view is that multiple dispatch is not worth the complexity it adds to a language. (2) it seems that an R specific IDE would improve productivity dramatically (maybe even necessary?) with respect to oop. Is there such an IDE and does it work for oop? I recall a group (in Germany?) was working on it but I can't remember where I read about it. -- Jeff __ 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] things that are difficult/impossible to do in SAS or SPSSbut simple in R
Frank E Harrell Jr [EMAIL PROTECTED] writes: Rob Robinson wrote: I wonder if those who complain about SAS as a programming environment have discovered SAS/IML which provides a programming environment akin to Matlab which is more than capable (at least for those problems which can be treated with a matrix like approach). As someone who uses both SAS and R - graphical output is so much easier in R, but for handling large 'messy' datasets SAS wins hands down... Cheers Rob My understanding is that PROC IML is disconnected from the rest of the SAS language, e.g., you can't have a loop in which PROC GENMOD is called or datasets are merged. If that's the case, IML is not very competitive in my view. I know about IML, but have never really used it. Back when I was doing that kind of stuff (before discovering S-Plus) I used GAUSS for compute-intensive matrix simulations and the like. I didn't have SAS for my PC, and there was no way I could tie up the Sun boxes at work with simulations for my thesis. But while IML does some nice stuff, it just reinforces the point I made in another post about the proliferation of little languages in SAS. By my count, that are now 5: 1. data step programming 2. macros -- a 'language' grafted on top of data step programming 3. scl -- if you want to do any kind of user interface 4. af -- object-oriented framework built on top of scl 5. iml -- matrix language like GAUSS, but doesn't play well with 1:4 above. To be a competent SAS programmer you need to keep 5 different languages with 5 different sets of rules in your head while you're coding. I can't do this, and I've never met anyone who could. The SAS programmers I've worked with all had to consult manuals or example code frequently to figure out how to do anything complicated. With R, you just write it. I've rewritten a number of ugly SAS programs in R. Typically, the R code is a third or less the size of the SAS code, although I just did a program a couple of days ago in which 112 lines of R replaced two SAS programs totalling 1900 lines of code, for an 18:1 reduction. Now you could argue that those were poorly-written SAS programs, and I would agree. But in my experience, most SAS programs are poorly written. SAS provides such poor programming tools that most good programmers move on to something else as soon as they can. Jeff __ 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] things that are difficult/impossible to do in SAS or SPSS but simple in R
SAS has no facilities for date arithmetic and no easy way to build it yourself. In fact, that's the biggest problem with SAS: it stinks as a programming environment, so it's always much more difficult than it should be to do something new. As soon as you get away from the canned procs and have to write something of your own, SAS falls down. I don't know enough about SPSS to comment. -- Jeff __ 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] is it safe to replace every - by = in R code?
Jonathan Baron [EMAIL PROTECTED] writes: I think it is worth pointing out that, if you use ESS with (X)emacs, - (with spaces) is produced when you type _. It requires only two keystrokes (shift and -), and the spaces are done for you. The = sign requires three because you need to type the spaces on each side. Is there a way to turn this off? I sometimes have to use variable names with underscores in them (not by my choice) and having to defeat ESS's attempts to replace the underscores with '-' can really be annoying. -- Jeff __ 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] I need arguments pro-S-PLUS and against SAS...
SAS programming is easy if everything you want to do fits easily into the row-at-a-time DATA step paradigm. If it doesn't, you have to write macros, which are an abomination. DATA step statements and macros are entirely different programming languages, with one doing evaluations at compile time, and the other at run time. Except that that's not really true, either, witness the 'call symput()' construct. Then, if you want to interact at all with the user, you need to learn SCL, a third language, with it's own rules. And to do anything sophisticated with a user interface (which will still look like hell), you have to learn the SAS A/F toolkit built on SCL. And of course, A/F requires you to think differently yet again. So, to be a competent and versatile SAS programmer, you have to learn four languages and four paradigms, and keep them all straight in your head while programming. Of course, hardly anyone can do this, so you usually find stacks of reference documentation close at hand when you visit a SAS programmer's office. R and Splus don't offer much in the way of GUI programming, but for problems that don't require a lot of GUI, it's very nice. You learn one language, it's quite forgiving, it's interpreted and usually easy to debug, and the programs you end up with are far more readable and maintainable than anything a SAS programmer can turn out. Reading my own SAS code is bad, and reading someone else's is torture. Do I sound like an R bigot? Actually, I'm a Smalltalk bigot, which is even nicer than R. But R is quite usable for most things I do, and I use Smalltalk for GUI-intensive stuff. Speaking as a programmer, SAS is awful. -- Jeff __ 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.