Displaying 20 results from an estimated 10000 matches similar to: "Getting subsets of a data frame"
2005 Apr 27
3
Time series indexes
I tried to assign values to specific elements of a time series and got
in trouble. The code below should be almost self-explanatory. I wanted
to assign 0 to the first element of x, but instead I assigned zero to
the second element of x, which is not what I wanted. Is there a
function that will allow me to do this without going into index
arithmetic (which would be prone to errors)?
FS
>
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 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
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,
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
2001 Jul 09
1
polynomial regression and poly
When doing polynomial regression I believe it is a good idea to use the poly
function to generate orthogonal polynomials. When doing this in Splus there
is a handy function (transform.poly I think) to convert the coefficients
produced by regression with the poly function back to the original scale.
Has somebody written something similar for R ?
Robert
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 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
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
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 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 Nov 23
1
statistics help
hi
im a bioinformatics student as i have never had any previous programming
experience
i need help
this is the question i need to answer:
Random walk model
we want to model a random walk where you take a step to the left with
probability p
and one to the right with probability 1-p. Now assume that there is a line
of 11 squares.
once you are in square 0 or in square 10 the walk ends. The aim
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 Jan 10
2
select subsets in data frame
Dear WizaRds!
A trivial question indeed on selecting subsets in data frames. I am
sorry. Unfortunately, I did not find any helpful information on the
introduction, searched the help archive and read in introductory books.
Please help:
I want to select column "KB" which is read via read.csv2 as a data.frame
into d. I checked that it is indeed a data.frame object and included the
2008 Oct 21
3
R command line
Hi!
Is there a Gui for R with improvements in the command line? I'm not looking
for buttons, menus and etc, but (more) colored syntax, auto-complete
commands and etc?
Best regards,
Raphael Saldanha
saldanha.plangeo@gmail.com
[[alternative HTML version deleted]]
2009 Jul 03
2
R on flash
Hi!
Is there some R version for flashdisk, pendrive etc ?
--
Regards,
Raphael Saldanha
saldanha.plangeo@gmail.com
[[alternative HTML version deleted]]
2011 Nov 29
1
Read TXT file with variable separation
Hi!
I have to import some TXT files into R, but the separation between the
columns are made with different blank spaces, but each file use the
same separation. Example:
31 104 5 0 11RUA SAO
SEBASTIAO 25
BAIRRO FILETO
01