Skip to content
Prev 316459 / 398506 Next

Creating dummy variables in r

On Jan 30, 2013, at 04:58 , Bert Gunter wrote:

            
In this case it's a cutpoint-type situation, and the user might be excused for not wanting to deal with the mysteries of cut() (yet). 

More importantly, the main issue here seems to be a lack of understanding of where new variables are located. I.e., if the data set is called dd, you need

dd$prev1 <- (etc)

and if you use attach(), do it _after_ modifying the data (or detach() and reattach).

Otherwise, new variables end up in the global environment. (This is logical enough once you realize that the result of a computation does not necessarily "fit" into the dataset.)

By the way: You don't need ifelse(): as.numeric(ret1 >= .5) or even just (ret1 >= .5) works.