How do I create dummy variables with if statements?
显示 更早的评论
I have a dataset with excess return, R, which consists of 10 000 rows and 1 column.
I want to create a new variable X that takes the value of 1 for each row in R if R>0 for all rows in R. And it takes the value of 0 if R<0.
Probably a simple question, but couldnt find any other answers out there that worked for me.
回答(1 个)
madhan ravi
2020-11-6
编辑:madhan ravi
2020-11-6
X = R > 0
5 个评论
Walter Roberson
2020-11-6
X = nan(size(R));
X(R > 0) = 1;
X(R < 0) = 0;
The nan is needed because the user did not define the result for R == 0 exactly.
madhan ravi
2020-11-6
Thank you sir Walter
Tobias M
2020-11-6
Tobias M
2020-11-6
madhan ravi
2020-11-6
So I won't "predict" anything.
类别
在 帮助中心 和 File Exchange 中查找有关 Random Number Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!