Identify binary columns

后端 未结 2 1419
悲&欢浪女
悲&欢浪女 2020-12-20 14:01

I would like to identify binary columns in a data.frame.

For example, this table

my.table <-read.table(text=\"a,b,c
0,2,0
0.25,1,1
1,0,0\", header         


        
2条回答
  •  情话喂你
    2020-12-20 14:50

    apply(my.table,2,function(x) { all(x %in% 0:1) })
    

    (or

    apply(my.table,2,function(x) { all(na.omit(x) %in% 0:1) })
    

    if you want to allow for NA values)

提交回复
热议问题