r - Setting indicator variables to equal 1 or 0 -
i have set higpa equal 1 if gpa greater 3, , if less, higpa must equal 0. using r.
gpa variable in data. higpa not. far have made higpa factor of gpa.
> higpa<-factor(gpa) after step lost.
thank help!
you should post example data... so:
gpa <- c(2, 3.68, 2.96, 2.85, 2.67, 3.26, 2.55, 2.84, 3.09, 2.79) here's 1 way:
as.numeric(gpa >= 3) [1] 0 1 0 0 0 1 0 0 1 0 so can put higpa
higpa <- as.numeric(gpa >= 3) if need factor, can factor or as.factor @ end.
Comments
Post a Comment