Home > other >  Extract rows in R dataframe which aligns with dummyvariable
Extract rows in R dataframe which aligns with dummyvariable

Time:01-26

I would like to create one vector of every MKT observation for when the dummy variable equals 1 and another vector when dummy equals 0.

This is how my dataframe looks:

enter image description here

CodePudding user response:

Easy solution with dplyr:

df_new <- filter(SP500.df, dummy == 1)

CodePudding user response:

You can do this with base R as well.

## Case when dummy = 1
MKT_vector = SP500.df[SP500.df$dummy==1,]$MKT
  •  Tags:  
  • Related