Your first replacement in kx changed it to a character vector and
comparisons
of character strings given different results than comparisons of numbers
> kx <- 1:10
> qt <- quantile(kx)
> kx[kx <= qt[2]] <- "DN"
> kx
[1] "DN" "DN" "DN" "4" "5" "6" "7" "8" "9" "10"
> "10" < "6"
[1] TRUE
>
> #
Your goal is fundamentally flawed, since all elements of a vector must be if
the same type.
Create another vector to hold your character information.
kc <- rep( 'NC', length( kx ) )
kc[ kx <= qt[[2]] ] <- 'DN'
kc[ kx >=qt [[4]] ] <- 'UP'
--
Sent from my phone. Please excuse my brevity.
On N
Hi group,
I have a vector of numeric items and I want to replace based on
logical operator (> or <) with 'up', 'down' or 'nochange'
The way I am doing works sometimes and does not work sometime. I dont
understand the problem. In this example, that works for condition DN
first, gets over-written
3 matches
Mail list logo