Creating Factor Vector

Hello I am trying to create the below vector but I am getting the error:Error in RD_Exp$TENURE : $ operator is invalid for atomic vectors. can anyone advise how to overcome this? thanks in advance

RD_Exp <-factor(RD_Exp$RACE,
levels =c(1,2,3,4,5,6,7),**

It seems that RD_Exp is a vector. What is the result of


Did you perhaps mean to write something like

RD_Exp$RACE <-factor(RD_Exp$RACE)

at an earlier step so that you would replace the value of the RACE column? If RD_Exp is a data frame and you write

RD_Exp <-factor(RD_Exp$RACE)

the data frame will become a vector.

1 Like

Thank you so much, you are right I skipped a step, good to go now!