Select rows in a dataframe in r based on values in one row

后端 未结 1 1152
半阙折子戏
半阙折子戏 2020-12-18 03:01

I have a toy data-frame.

a = rep(1:5, each=3)
b = rep(c(\"a\",\"b\",\"c\"), each = 5)
df = data.frame(a,b)

   a b
1  1 a
2  1 a
3  1 a
4  2 a
5  2 a
6  2 b
         


        
相关标签:
1条回答
  • 2020-12-18 03:54

    Use the %in% argument

    df[df$a %in% idx,] 
    
    0 讨论(0)
提交回复
热议问题