Displaying 20 results from an estimated 20000 matches similar to: "Time series indexes"
2005 Apr 26
2
Extending time series
I noticed that when one tries to extend a time series (ts) object by a
single period using window() actually two observations (NAs) are
added. See below for an example. Does anyone know the reason for this
behavior and how to avoid it?
Thanks.
FS
> x<-ts(c(1,2,3))
> x1<- window(x, start(x), end(x) + 1, extend = TRUE)
> x1
Time Series:
Start = 1
End = 5
Frequency = 1
[1] 1 2
2005 Apr 26
1
Time alignment of time series
One thing that has given me trouble is the fact that the time series
implementation in the class ts relies on the concept of a "start" to
the time series. For example, if I have
ts1 <- ts(c(1,2,3))
dts1 <- diff(ts1)
then dts1 will be a vector c(1,1) but with the attribute start = 2.
Similarly, when one takes lags the "start" is moved around and the
underlying vector
2005 Apr 12
1
Regression and time series
Can someone shed some light on this obscure portion of the help for lm?
"Considerable care is needed when using 'lm' with time series.
Unless 'na.action = NULL', the time series attributes are stripped
from the variables before the regression is done. (This is
necessary as omitting 'NA's would invalidate the time series
attributes, and if
2006 Feb 02
2
How to get the namespace of a function?
I declared the environment of the function myfun to be NULL as follows:
environment(myfun) <- NULL
Later on I called that myfun and got an error message because the
function index() in the zoo package was called inside myfun and was
not visible:
Error in myfun(args) : couldn't find function "index"
I tried to use zoo::index() instead of index(), but that did not work.
In fact,
2006 May 20
3
sapply and Date objects
This is probably a dumb question, but I cannot figure it out. Why does
this happen?
dt <- as.Date("1954-02-01")
> as.character(dt)
[1] "1954-02-01"
> sapply(c(dt), as.character)
[1] "-5813"
Thanks.
FS
2005 Apr 27
3
assign to an element of a vector
I am trying to find a way to assign values to elements of a vector
that will be defined by a user. So I don't have the name of the vector
and cannot hard code the assignment in advance. In the example below I
have to get() the vector using its name. When I try to assign to an
element I get an error:
> a <- c(1,2,3)
> get('a')[1] <- 0
Error: Target of assignment expands to
2005 Apr 15
2
Define "local" function
I discovered a bug in a program I am writing which was due to the
program using a global variable within a function.
For example,
myfunc <- function(x) { y}
That is, I made a mistake when defining the function and wrote "y"
when I should have written "x".
However, there was a variable y in the global environment and the
function "worked" but gave the wrong
2008 Mar 22
1
Geting names of variables
I wanted to create a list with the names of variables and their
values. So I wrote the following function.
add.to.list.names.vars.1 <- function(lnv, vnv) {
i <- 1
while (i < length(vnv)) {
z <- as.character(eval(substitute(quote(vnv[i+1])))[[2]][[i + 2]])
lnv[[vnv[i]]] <- list(Name = z, Value = vnv[i+1])
i <- i + 2
}
lnv
}
It works, but it is very
2008 Apr 27
1
system.time()
I thought system.time() would return three numbers, the first two
adding up to the third one. However, this does not hold in my system
running Windows Vista Home Premium, with an Intel Core 2 Duo
processor. For example, using the code in the help for system.time()
(with one zero added), I got:
> system.time(for(i in 1:100) mad(runif(10000)))
user system elapsed
0.27 0.00 0.25
Is
2011 Oct 27
1
plotting large time series
hello,
I got a problem with plotting large time series, since I want to store
the results in a .PDF file (I want to store several pages of plots). The
PDF files get too large to be handled (> 10MB, one was even 200MB big).
So I wonder, if there would be a possibilty to either
- reduce the file size of the PDF
- change the way the plot is generated to reduce the plot size?
I use:
2008 Dec 02
4
Variables inside a for
Hi!
I had a database with some variables in sequence. Let me say: TX01, TX02,
TX03 and TX04.
But I need to run some regressions changing the variables... so:
variable <- paste("TX0", 1:4, sep="")
for(i in 1:4){
test[i] <- lm(variable[i] ~ INCOME, data=database)
}
But doesn't work... lm tries to find a variable inside database named
variable[i] ...
Suggestions?
2005 Apr 16
2
Getting subsets of a data frame
I was reading in the Reference Manual about Extract.data.frame.
There is a list of examples of expressions using [ and [[, with the
outcomes. I was puzzled by the fact that, if sw is a data frame, then
sw[, 1:3]
is also a data frame,
but
sw[, 1]
is just a vector.
Since R has no scalars, it must be the case that 1 and 1:1 are the same:
> 1 == 1:1
[1] TRUE
Then why isn't sw[,1] =
2008 Jan 16
3
Rprofile.site not executed?
It seems that my Rprofile.site file is not executed when I start R. To
test this I included the following code in that file:
.First <- function(){
cat("\nWelcome at", date(), "\n")
flush.console()
}
When I start R the message above is not displayed.
I am running R 2.6.1 (rgui.exe) under Vista Home Premium. The
Rprofile.site is in the etc folder and the R_PROFILE
2005 May 10
6
Does R have a command for sending emails?
Is there a way to have an R program send an email?
Something like this:
address <- 'abc at d.com'
text <- 'This is the email body'
send.email(address, text)
Thanks.
FS
2005 Nov 11
3
Inputing data from multiple files as time series objects
Hello to everyone,...
I am a new R ambitious user. I would like to be the first at my
department using R, but I have encountered a difficulty during the
last days that I cannot overcome reading help() and searching over the
net.
Problem:
I have multiple files with financial data like the following (header included):
E.g.:
filename: AOL.txt
aol.txt
4
3
5
3...
filename: IBM.txt
ibm.txt
6
2
5
2...
2005 Nov 15
2
Subtracting timeseries objects
Sorry to keep posting but I want to do this right and I'm hoping for
some pointers
I now have two time series objects which I need to subtract.
Unfortunatly the two series dont have the same sample rates.
When I try to subtract them
avgSub<-avg1-avg2
The time series object is clever enough to object.
So I guess I need to write a function for subtraction of the time series
objects which
2006 Nov 23
1
dumping/loading objects with 'tsp' attribute
Dear all,
I'm indirectly faced with the fact that setting the 'tsp' attribute of
an object modifies its class definition:
> class( structure(1:2, tsp=c(1,2,1), class=c("myts","ts")) )
[1] "ts" "myts"
In general, this is of really little (ok, I admit: totally no)
interest for me because 'myts' class is added just after assigning the
2004 Jun 22
2
ts & daily timeseries
I have defined a daily timeseries for the 365 days of 2003 issuing:
myts = ts(dati[,2:10],frequency=365,)
> myts
Time Series:
Start = c(1, 1)
End = c(1, 365)
Frequency = 365
and
mytime = as.POSIXct(strptime(as.character(dati[,1]),format="%Y-%m-%d"))
contains the dates from "2003-01-01" to "2003-12-31"
How can I combine mytime and myts in order to list
2006 May 01
1
Problem with optim()
I am having a problem with optim() using the "L-BFGS-B" method. When I
set the lower limit for the third parameter equal to zero I get an
error message:
> low.lim.3 <- 0
> phi_opt <- optim(phi_, model_lik, NULL, method = "L-BFGS-B", lower=c(0.2, -100, low.lim.3, 0), upper= c(10, 100, 10, 10), control = list(maxit = 1000, parscale = c(0.2, u1, 0.002, 0.002), trace =
2007 Nov 05
5
Sending E-Mail from R
Hi,
Has anyone used R to send out an email via an SMTP server? I run R from a
script and would like to be able to send out an email from there also. I
could shell out to an email program, but was hoping maybe someone had a
package for R or a smooth way to do it.
Thanks,
Josh
[[alternative HTML version deleted]]