'Extract rows in R dataframe which aligns with dummyvariable
Solution 1:[1]
Easy solution with dplyr:
df_new <- filter(SP500.df, dummy == 1)
Solution 2:[2]
You can do this with base R as well.
## Case when dummy = 1
MKT_vector = SP500.df[SP500.df$dummy==1,]$MKT
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | geoff |
| Solution 2 | Deepansh Arora |

