Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 209819

how can I set a dummy variable in a regression in R

$
0
0

The following is my data

y   r1  r2  r3

1   0.1 0.2 -0.3
2   0.7 -0.9    0.03
3   -0.93   -0.32   -0.22

1.The first question is how can I get the output like this:

y   r1     r2    r3    dummy_r1  dummy_r2 dummy_r3

1   0.1    0.2   -0.3    0        0          1
2   0.7   -0.9   0.03    0        1          0
3   -0.93 -0.32  -0.22   1        1          1

Note:I want the negative data equals to 1, and the positive data equals to 0

2.The second question is that if I want to do the regression like: lm(y~r1+r2+r3+dummy_r1+ dummy_r2+dummy_r3),what should I do if I don’t want to use the output data(dummy_r1,dummy_r2,dummy_r3) above, because it is not convenient.


Viewing all articles
Browse latest Browse all 209819

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>