[R] Changing 2 Numeric Variables to 1 Categorical Variable in R?

#1
I am a finance student and have been playing around in R the past couple of weeks (Rookie here..).
QUESTION: I have two numeric variables: A and B. And I want turn these in one cathegorical variable C. C takes the following values:
1 if A and B both score top decile – or quintile of the distribution.
0 otherwise

Does anyone have any idea how to effectuate this? Thank you in advance!
 
#2
Hi,

decile/quintile of their own distribution? In this case:


quantile <- 0.6
A <- rnorm(mean=0,sd=1,100)
B <- rnorm(mean=0,sd=1,100)
C <- as.numeric()
C <- ifelse( (A > quantile(A, quantile )) & (B > quantile(B, quantile )) ,1,0 )
C <- factor(C)
C