[R] R Help
Ben Bolker
bolker at ufl.edu
Tue Oct 21 23:32:45 CEST 2008
Boyce, Morgan <morgan.boyce <at> bankofamerica.com> writes:
>
> y.JIBqq[,1][y.JIBqq[,1]> y.JIBqq[,2]]<-'up move'
> y.JIBqq[,1][y.JIBqq[,1]< y.JIBqq[,2]]<-'down move'
Your first command above makes y.JIBqq[,1] into a
character vector (rather than numeric), which then
makes the subsequent comparison complicated/tricky
(it will be a lexical, rather than a numeric one --
for example, consider the fact that
"-0.01">"0.001" is TRUE)
A better way to do what you want is
probably something like
## read in data
x <- read.table("miscdate.txt",
colClasses=c("Date","numeric","numeric"))
rownames(x) <- as.character(x[,1])
x <- x[,-1]
## at this point I have something like your y.JIBqq
move <- ifelse(x[,1]>x[,2],'up move','down move')
x <- data.frame(x,move)
More information about the R-help
mailing list