Convert a vector into logical matrix

后端 未结 2 880
眼角桃花
眼角桃花 2021-01-26 03:00

Is there a native R function that will take an input vector and return the corresponding binary matrix where the matrix has the same number of columns as unique values in the in

2条回答
  •  花落未央
    2021-01-26 03:29

    Actually, contrasts is what you want.

    contrasts(as.factor(1:3), contrasts=FALSE)
    
      1 2 3
    1 1 0 0
    2 0 1 0
    3 0 0 1
    

提交回复
热议问题